/* =====================================================================
   "Paper cutout" style — ContractorDashboard's look of the instruction
   videos: construction paper cut out and laid on a sunburst. Plain
   off-white paper, navy ink, a coral dot, mustard for whatever is
   selected, Luckiest Guy for titles and Nunito for everything else.

   Active while <html data-theme="papercut"> (js/theme.js); app.css alone
   is the "Original" style. Every rule below sits inside @scope, whose root
   adds no specificity: each replaces exactly the app.css rule with the same
   selector and loses to the same rules that one loses to. That is
   load-bearing — the flat utility buttons (.small-btn, #schedule .cell-btn,
   .rec-dialog-x, ...) only stay flat because one class outranks the bare
   `button` rule, and a heavier theme selector would put a navy card behind
   every table icon.

   Most of the look rides on app.css's own variables (--gradient-dark is
   flat ink, so every section header, button and the sidenav follow).
   Coloured cells (schedule, payments, streaks) are left alone: their
   colours carry meaning.

   Tilts use the `rotate` property rather than `transform`, so they compose
   with the transforms app.css already animates on hover.
   ===================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Luckiest+Guy&family=Nunito:wght@400..900&display=swap');

html[data-theme="papercut"] {
    --ink: #1b2a41;
    --paper: #fbf7ee;
    --paper-2: #f4ecdb;
    --paper-3: #ebdfc6;
    --field: #fffdf8;
    --pc-blue: #2f74d0;
    --pc-blue-ink: #1f56a8;
    --pc-coral: #e8535d;
    --pc-mustard: #f6c343;
    --pc-green: #2e8b57;
    --tape: rgba(255, 246, 214, 0.62);

    --bg: var(--pc-blue);
    --text-dark: var(--ink);
    --text-secondary: #5d6577;
    --border: #d9ccb0;
    --divider: #ece3cf;
    --radius: 5px;
    --radius-sm: 4px;

    --gradient-dark: linear-gradient(var(--ink), var(--ink));
    --gradient-info: linear-gradient(var(--pc-blue), var(--pc-blue));
    --gradient-success: linear-gradient(var(--pc-green), var(--pc-green));
    --gradient-warning: linear-gradient(var(--pc-mustard), var(--pc-mustard));
    --gradient-danger: linear-gradient(var(--pc-coral), var(--pc-coral));

    /* Paper lying on paper: a thin hard edge plus a soft drop underneath */
    --shadow-card: 1px 2px 0 rgba(27, 42, 65, 0.08), 3px 6px 14px rgba(15, 30, 70, 0.28);
    --shadow-header: 2px 3px 0 rgba(0, 0, 0, 0.18), 0 6px 12px rgba(0, 0, 0, 0.18);
    --shadow-btn: 0 3px 0 rgba(0, 0, 0, 0.3);
}

@scope (html[data-theme="papercut"]) {

    /* -----------------------------------------------------------------
       Base
       ----------------------------------------------------------------- */

    body {
        font-family: "Nunito", "Roboto", system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
        font-weight: 500;
        background-color: var(--pc-blue);
        /* The sunburst every title card in the videos sits on */
        background-image:
            radial-gradient(ellipse at 50% 35%, transparent 35%, rgba(12, 30, 75, 0.35)),
            repeating-conic-gradient(from -4deg at 50% 38%, #3479d6 0deg 9deg, #2c6bcb 9deg 18deg);
        background-attachment: fixed;
    }

    h1, h2, h3 {
        font-family: "Luckiest Guy", "Nunito", sans-serif;
        font-weight: 400;
        font-synthesis: none;
        letter-spacing: 0.03em;
        line-height: 1.15;
    }

    a, nav a, .auth-links a { color: var(--pc-blue-ink); }

    ::selection { background: var(--pc-mustard); color: var(--ink); }

    /* -----------------------------------------------------------------
       Page header: a strip of paper, the truck in a coral circle
       ----------------------------------------------------------------- */

    header { background: var(--paper); box-shadow: var(--shadow-header); }

    header h1 .subtitle {
        font-family: "Luckiest Guy", "Nunito", sans-serif;
        font-size: 1.05rem;
        letter-spacing: 0.04em;
        color: var(--ink);
    }

    header h1 .brand-icon {
        display: inline-grid;
        place-items: center;
        width: 2.4rem;
        height: 2.4rem;
        border-radius: 50%;
        background: var(--pc-coral);
        color: #fff;
        font-size: 1.35rem;
        box-shadow: 1px 2px 0 rgba(0, 0, 0, 0.3);
        rotate: -8deg;
    }

    /* -----------------------------------------------------------------
       Forms
       ----------------------------------------------------------------- */

    label { color: var(--ink); font-weight: 800; }

    input, select {
        font-weight: 600;
        background: var(--field);
        border: 2px solid var(--border);
        border-radius: 4px;
        accent-color: var(--pc-coral);
    }

    input:focus, select:focus {
        border-color: var(--ink);
        box-shadow: 0 0 0 3px rgba(246, 195, 67, 0.6);
    }

    textarea { background: var(--field); border: 2px solid var(--border); border-radius: 4px; }

    /* -----------------------------------------------------------------
       Buttons: navy card stock, tipping over a little when pointed at
       ----------------------------------------------------------------- */

    button {
        border-radius: 4px;
        font-weight: 800;
        letter-spacing: 0.03em;
        box-shadow: 0 3px 0 rgba(0, 0, 0, 0.3), 0 5px 10px rgba(0, 0, 0, 0.15);
        transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.12s ease;
    }

    button:hover {
        transform: translateY(-1px) rotate(-1.5deg);
        box-shadow: 0 4px 0 rgba(0, 0, 0, 0.3), 0 8px 14px rgba(0, 0, 0, 0.2);
        opacity: 1;
    }

    button:disabled { opacity: 0.5; transform: none; box-shadow: 0 3px 0 rgba(0, 0, 0, 0.3); }

    /* The small buttons are cut from card too: paper with an ink edge and a hard
       shadow, leaning over when pointed at (rotate composes with the transform
       app.css resets on hover). */
    .small-btn {
        background: var(--paper);
        color: var(--ink);
        border: 2px solid var(--ink);
        border-radius: 3px;
        font-weight: 800;
        box-shadow: 2px 2px 0 rgba(27, 42, 65, 0.35);
        transition: rotate 0.12s ease, background-color 0.12s ease;
    }
    .small-btn:hover { background: #fbe8a6; rotate: -1.5deg; }
    .small-btn:disabled { rotate: none; background: var(--paper-2); box-shadow: none; }

    /* Toggle rows (weekdays, Unassigned/All): one strip of card, the lit
       segments mustard tiles; the strip carries the shadow, not each piece */
    .btn-toggle { box-shadow: 2px 2px 0 rgba(27, 42, 65, 0.35); border-radius: 3px; }
    .btn-toggle .small-btn { box-shadow: none; rotate: none; }
    .btn-toggle .small-btn.active { background: var(--pc-mustard); color: var(--ink); border-color: var(--ink); }
    .btn-toggle .small-btn.active + .small-btn { border-left-color: var(--ink); }
    #ord-days .small-btn.weekend:not(.active) { color: var(--pc-coral); }

    /* -----------------------------------------------------------------
       Messages
       ----------------------------------------------------------------- */

    .message { border-radius: 3px; font-weight: 600; }
    .message.success { background: #e1f0e4; color: #1d5e3a; border: 2px solid #b5d9c0; }
    .message.error   { background: #fbe4e2; color: #8e2430; border: 2px solid #f1b9b9; }
    .message.warning { background: #fdf0cc; color: #6f4b00; border: 2px solid #f0d27f; }

    .info-box { background: #fdf0cc; color: #6f4b00; border: 2px solid #f0d27f; border-radius: 3px; }
    .pending-box { background: var(--paper-2); color: var(--ink); border: 2px solid var(--border); border-radius: 3px; }

    pre { background: var(--field); border: 2px solid var(--border); }

    /* -----------------------------------------------------------------
       Auth pages: a paper card taped to the sunburst
       ----------------------------------------------------------------- */

    main.login {
        position: relative;
        background: var(--paper);
        border-radius: 3px;
    }

    main.login::before {
        content: "";
        position: absolute;
        z-index: 2;
        top: -2.2rem;
        left: 50%;
        width: 7rem;
        height: 1.7rem;
        margin-left: -3.5rem;
        background: var(--tape);
        box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
        rotate: -4deg;
    }

    main.login > h1 {
        font-size: 1.7rem;
        letter-spacing: 0.04em;
        border-radius: 3px;
        rotate: -1.5deg;
    }

    /* -----------------------------------------------------------------
       Section cards: paper, the header a tilted navy banner
       ----------------------------------------------------------------- */

    .section,
    #section-content > section { background: var(--paper); border-radius: 4px; }

    .section > h2,
    #section-content > section > h2,
    .section > .collapsible > summary {
        font-family: "Luckiest Guy", "Nunito", sans-serif;
        font-weight: 400;
        font-size: 1.2rem;
        letter-spacing: 0.04em;
        border-radius: 3px;
        rotate: -0.6deg;
    }

    /* orders.html pins its title under the page header with a backing behind
       it; a tilt would open gaps at the corners as the list scrolls under. */
    .section > #ord-title { rotate: none; }
    #ord-title::before, #ord-form { background: var(--paper); }
    #ord-form { border-bottom: 2px dashed var(--border); }
    #ord-form .ord-field { color: var(--ink); font-weight: 800; }
    #ord-search-helpbox { background: var(--paper); border: 2px solid var(--ink); box-shadow: 3px 4px 0 rgba(27, 42, 65, 0.3); }
    #ord-search-helpbox tr[data-field]:hover td { background: #fbe8a6; }

    /* The order list's column headings: a navy strip lettered in the title
       font, the search boxes under it on kraft */
    #ord-table thead th {
        background: var(--ink);
        color: var(--paper);
        font-family: "Luckiest Guy", "Nunito", sans-serif;
        font-weight: 400;
        font-size: 0.85rem;
        letter-spacing: 0.06em;
        text-transform: none;
        border-bottom: 0;
        box-shadow: none;
    }
    #ord-table .colsearch-row td { background: var(--paper-2); box-shadow: inset 0 -2px 0 var(--border); }
    #ord-table .colsearch { background: var(--field); border: 2px solid var(--border); border-radius: 3px; }
    #ord-table .colsearch:focus { border-color: var(--ink); }
    #ord-table td.daycell { background: var(--paper-2); border-right: 2px dashed var(--border); }
    #ord-table tbody tr.orderrow:hover td { background: #fbe8a6; }
    #ord-table tbody tr.orderrow:hover td.daycell { background: var(--paper-2); }

    /* -----------------------------------------------------------------
       Sidenav: a strip of navy card, the open section a mustard tile
       ----------------------------------------------------------------- */

    #section-nav {
        border-radius: 4px;
        box-shadow: 3px 5px 0 rgba(0, 0, 0, 0.2), 0 10px 24px rgba(0, 0, 0, 0.25);
    }

    #section-nav button { font-weight: 700; border-radius: 3px; }

    #section-nav button:hover { background: rgba(255, 255, 255, 0.1); rotate: -0.6deg; }

    /* The open section is a mustard tile, cut by hand: the tabs take turns
       through five shapes and tilts, so the tile changes form as you move
       through the menu. The tile is ::before so clip-path can cut it without
       cutting the text; the drop shadow is a filter on the button, since a
       box-shadow would be clipped away along with the corners. */
    #section-nav button.active {
        position: relative;
        z-index: 0;
        background: none;
        box-shadow: none;
        color: var(--ink);
        font-weight: 800;
        filter: drop-shadow(2px 3px 0 rgba(0, 0, 0, 0.3));
        rotate: var(--tile-tilt, -1.5deg);
    }

    #section-nav button.active::before {
        content: "";
        position: absolute;
        inset: 0;
        z-index: -1;
        background: var(--pc-mustard);
        clip-path: var(--tile-shape, polygon(0 0, 100% 0, 100% 100%, 0 100%));
        animation: pc-tile-slap 0.18s ease-out;
    }

    #section-nav button:nth-child(5n+1) { --tile-tilt: -1.5deg; --tile-shape: polygon(0 26%, 6% 0, 100% 5%, 98% 100%, 1% 94%); }
    #section-nav button:nth-child(5n+2) { --tile-tilt: 1.2deg;  --tile-shape: polygon(2% 4%, 100% 0, 100% 66%, 93% 100%, 0 96%); }
    #section-nav button:nth-child(5n+3) { --tile-tilt: -0.8deg; --tile-shape: polygon(0 0, 92% 4%, 100% 34%, 99% 100%, 3% 95%); }
    #section-nav button:nth-child(5n+4) { --tile-tilt: 1.8deg;  --tile-shape: polygon(1% 7%, 98% 0, 100% 96%, 8% 100%, 0 68%); }
    #section-nav button:nth-child(5n+5) { --tile-tilt: -2deg;   --tile-shape: polygon(3% 0, 100% 9%, 97% 90%, 52% 100%, 0 95%); }

    /* -----------------------------------------------------------------
       Tables: a dashed cut line under the headings
       ----------------------------------------------------------------- */

    table { background: transparent; }

    th {
        background: var(--paper);
        color: var(--ink);
        font-weight: 900;
        letter-spacing: 0.07em;
        border-bottom: 2px dashed var(--border);
    }

    /* -----------------------------------------------------------------
       Cards in lists (readers, accounts, backups)
       ----------------------------------------------------------------- */

    .reader-card { background: var(--field); border: 2px solid var(--border); border-left: 4px solid transparent; }
    .reader-card:hover { background: var(--paper-3); }
    .reader-card[aria-pressed="true"] {
        background: var(--pc-mustard);
        border-color: var(--ink);
        box-shadow: 2px 3px 0 rgba(0, 0, 0, 0.22);
        rotate: -1deg;
    }

    #admin-users tr.acct-row:hover td { background: var(--paper-3); }
    #admin-users tr.acct-row.selected td { background: #fbe8a6; box-shadow: inset 4px 0 0 var(--ink); }

    .backup-card { background: var(--field); border: 2px solid var(--border); }
    .mw-card { background: var(--field); border: 2px solid var(--border); }
    .mw-tile { background: var(--paper-3); }

    /* -----------------------------------------------------------------
       Dialogs
       ----------------------------------------------------------------- */

    .rec-dialog, .pin-chats-dialog { background: var(--paper); border: 2px solid var(--ink); border-radius: 4px; }
    .rec-dialog::backdrop, .pin-chats-dialog::backdrop { background: rgba(15, 25, 50, 0.55); }
    .rec-dialog-head { border-bottom: 2px dashed var(--border); }

    /* -----------------------------------------------------------------
       Add / Edit order dialog: its sidebar is a strip of navy card like the
       dashboard's, the open part a mustard tile
       ----------------------------------------------------------------- */

    .oc-nav { background: var(--ink); border: 0; border-radius: 4px; box-shadow: 3px 4px 0 rgba(0, 0, 0, 0.2); }
    .oc-nav .oc-nav-btn { color: rgba(255, 255, 255, 0.85); font-weight: 700; border-radius: 3px; }
    .oc-nav .oc-nav-btn:hover { background: rgba(255, 255, 255, 0.1); rotate: -0.6deg; }
    .oc-nav .oc-nav-btn.active {
        background: var(--pc-mustard);
        color: var(--ink);
        font-weight: 800;
        box-shadow: 2px 3px 0 rgba(0, 0, 0, 0.3);
        rotate: -1.2deg;
    }
    .oc-nav .oc-nav-btn:nth-child(2).active { rotate: 1deg; }
    .oc-nav .oc-nav-btn:nth-child(3).active { rotate: -0.8deg; }
    .oc-nav .oc-nav-btn:nth-child(4).active { rotate: 1.4deg; }
    .oc-group { border: 2px solid var(--border); border-radius: 4px; background: var(--field); }
    .oc-group legend { color: var(--ink); font-weight: 900; }

    /* -----------------------------------------------------------------
       Live tracking: the tracker list as paper
       ----------------------------------------------------------------- */

    #devices, #replay-panel { background: var(--paper-2); }
    .device { background: var(--paper); }
    .device:hover { background: var(--paper-3); }
    .device.active { background: #fbe8a6; }
    .device.active::before { background: var(--pc-coral); }
}

/* The tile lands with a little slap, like paper put down on the table */
@keyframes pc-tile-slap {
    from { transform: scale(1.12) rotate(-3deg); opacity: 0.4; }
    to   { transform: none; opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
    :where(html[data-theme="papercut"]) #section-nav button.active::before { animation: none; }
}
