/* PWL Timesheet App — base styles */

:root {
    --bg-color: #f8fafc;
    --text-color: #1e293b;
    --card-bg: #ffffff;
    --border-color: #cbd5e1;
    --header-bg: #e2e8f0;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --success: #22c55e;
    --success-hover: #16a34a;
    --accent: #8b5cf6;
    --accent-hover: #7c3aed;
    --input-bg: #ffffff;
    --radius: 8px;
}

[data-theme="dark"] {
    --bg-color: #0f172a;
    --text-color: #f1f5f9;
    --card-bg: #1e293b;
    --border-color: #334155;
    --header-bg: #0f172a;
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --accent: #a78bfa;
    --accent-hover: #c4b5fd;
    --input-bg: #0f172a;
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
body { background-color: var(--bg-color); color: var(--text-color); transition: background-color 0.3s, color 0.3s; display: flex; flex-direction: column; min-height: 100vh; }

.side-panel { position: fixed; top: 50%; right: 20px; transform: translateY(-50%); z-index: 2000; display: flex; flex-direction: column; align-items: flex-end; gap: 10px; padding: 10px 15px 10px 10px; pointer-events: none; }
.side-panel button { pointer-events: auto; display: flex; align-items: center; justify-content: flex-end; width: 48px; height: 48px; border-radius: 24px; padding: 0 10px; background-color: var(--card-bg); color: var(--text-color); border: 2px solid var(--primary); box-shadow: -2px 4px 8px rgba(0,0,0,0.15); transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); overflow: hidden; white-space: nowrap; position: relative; }
.side-panel button:hover { width: 230px; background-color: var(--primary); color: white; }
.side-panel button .icon { font-size: 1.2rem; min-width: 24px; text-align: center; }
.side-panel button .text { margin-right: 12px; opacity: 0; transition: opacity 0.2s; font-weight: 600; font-size: 0.9rem; }
.side-panel button:hover .text { opacity: 1; transition-delay: 0.1s; }

header { text-align: center; padding: 2.5rem 2rem 1rem; }
h2 { font-weight: 700; font-size: 1.8rem; color: var(--text-color); }

button { padding: 8px 16px; border: none; border-radius: var(--radius); cursor: pointer; background-color: var(--primary); color: white; font-weight: 500; font-size: 0.9rem; transition: all 0.2s; display: flex; align-items: center; justify-content: center; gap: 6px; }
button:hover { background-color: var(--primary-hover); transform: translateY(-1px); }
.btn-danger { background-color: var(--danger); }
.btn-danger:hover { background-color: var(--danger-hover); }
.btn-wizard { background-color: var(--accent); font-weight: bold; }
.btn-wizard:hover { background-color: var(--accent-hover); }

.main-content { flex: 1; padding: 2rem 90px 2rem 2rem; max-width: 100%; overflow-x: hidden; }
.top-section { display: flex; flex-wrap: wrap; gap: 20px; margin-bottom: 20px; align-items: stretch; }
.meta-data { display: flex; flex-wrap: wrap; gap: 20px; background: var(--card-bg); padding: 20px; border-radius: var(--radius); border: 1px solid var(--border-color); box-shadow: 0 1px 3px rgba(0,0,0,0.05); flex: 1; }
.meta-data-row { display: flex; flex-direction: column; gap: 8px; flex: 1; min-width: 200px; }
.meta-data label { font-weight: 600; font-size: 0.85rem; color: var(--text-color); text-transform: uppercase; letter-spacing: 0.5px; }

.table-container { width: 100%; overflow-x: auto; background: var(--card-bg); border-radius: var(--radius); border: 1px solid var(--border-color); box-shadow: 0 1px 3px rgba(0,0,0,0.05); }
table { width: 100%; border-collapse: collapse; white-space: nowrap; }
th, td { border-bottom: 1px solid var(--border-color); padding: 10px 6px; text-align: center; border-right: none; }
th { background-color: var(--header-bg); font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-color); padding: 12px 6px; position: sticky; top: 0; z-index: 10; }
tr:last-child td { border-bottom: none; }

input, select { width: 100%; padding: 8px; border: 1px solid var(--border-color); border-radius: 4px; background: var(--input-bg); color: var(--text-color); font-size: 0.9rem; transition: border-color 0.2s, box-shadow 0.2s; }
select { cursor: pointer; appearance: none; background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%22//www.w3.org/2000/svg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%231e293b%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right .7rem top 50%; background-size: .65rem auto; padding-right: 1.5rem; }
[data-theme="dark"] select { background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%22//www.w3.org/2000/svg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%23f1f5f9%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22/%3E%3C/svg%3E"); }
input:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2); }
input[type="number"] { width: 60px; text-align: center; }

.smart-time { width: 75px; text-align: center; font-family: 'SFMono-Regular', Consolas, monospace; font-size: 0.9rem; letter-spacing: 0.5px; background-color: var(--header-bg); border: 1px solid transparent; border-radius: 6px; color: var(--text-color); }
.smart-time:focus { background-color: var(--input-bg); border-color: var(--primary); }
.advance-input { color: #ef4444; font-weight: 500; width: 80px; }
.add-row-btn { margin-top: 15px; background-color: var(--success); }
.add-row-btn:hover { background-color: var(--success-hover); }
footer { text-align: center; padding: 1.5rem; background-color: var(--card-bg); border-top: 1px solid var(--border-color); font-size: 0.85rem; color: var(--text-color); opacity: 0.8; }

/* Modal Styles */
.modal { display: none; position: fixed; z-index: 1000; left: 0; top: 0; width: 100%; height: 100%; background-color: rgba(0,0,0,0.5); backdrop-filter: blur(4px); justify-content: center; align-items: center; opacity: 0; transition: opacity 0.3s ease; }
.modal.show { display: flex; opacity: 1; }
.modal-content { background-color: var(--card-bg); padding: 25px; border-radius: var(--radius); width: 90%; max-width: 500px; max-height: 90vh; overflow-y: auto; text-align: center; border: 1px solid var(--border-color); box-shadow: 0 10px 25px rgba(0,0,0,0.1); transform: translateY(-20px); transition: transform 0.3s ease; position: relative; }
.modal-content.wide { max-width: 800px; }
.modal.show .modal-content { transform: translateY(0); }
.modal-content h3 { margin-bottom: 20px; font-size: 1.25rem; color: var(--primary); }
.modal-content button.block-btn { margin: 8px 0; width: 100%; padding: 12px; font-size: 1rem; }
.modal-content .close-btn { background-color: transparent; color: var(--text-color); border: 1px solid var(--border-color); }
.modal-content .close-btn:hover { background-color: var(--header-bg); }

/* Wizard Specific Styles */
.wiz-step { display: none; }
.wiz-step.active { display: block; animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.wiz-mode-btn { background-color: var(--bg-color); color: var(--text-color); border: 2px solid var(--border-color); opacity: 0.7; }
.wiz-mode-btn.selected { border-color: var(--primary); background-color: rgba(59, 130, 246, 0.1); color: var(--primary); opacity: 1; font-weight: bold; }

.wiz-form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; text-align: left; margin: 15px 0; background: var(--bg-color); padding: 15px; border-radius: var(--radius); border: 1px solid var(--border-color); }
.wiz-form-grid label { font-size: 0.75rem; font-weight: bold; color: var(--text-color); margin-bottom: 4px; display: block; text-transform: uppercase; }
.wiz-form-grid .full-width { grid-column: span 2; }

.wiz-pending-badge { display: inline-block; background: var(--header-bg); padding: 4px 10px; border-radius: 20px; font-size: 0.8rem; font-weight: 500; margin: 4px; color: var(--text-color); border: 1px solid var(--border-color); }
.wiz-inner-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.wiz-inner-table th { background: var(--header-bg); padding: 8px; border: 1px solid var(--border-color); }
.wiz-inner-table td { padding: 4px; border: 1px solid var(--border-color); }
.wiz-inner-table input, .wiz-inner-table select { padding: 6px; font-size: 0.85rem; }

.wiz-checkbox-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; text-align: left; max-height: 40vh; overflow-y: auto; background: var(--bg-color); padding: 10px; border: 1px solid var(--border-color); border-radius: var(--radius); }
.wiz-checkbox-grid label { display: flex; align-items: center; gap: 8px; padding: 8px; background: var(--card-bg); border: 1px solid var(--border-color); border-radius: 4px; cursor: pointer; }
.wiz-checkbox-grid label:hover { border-color: var(--primary); }

.toast { position: fixed; bottom: 20px; right: 20px; background-color: var(--success); color: white; padding: 12px 24px; border-radius: var(--radius); box-shadow: 0 4px 12px rgba(0,0,0,0.15); z-index: 5000; transform: translateY(100px); opacity: 0; transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55); font-weight: 500; }
.toast.show { transform: translateY(0); opacity: 1; }

.undo-toast { position: fixed; bottom: 20px; right: 20px; background-color: var(--text-color); color: var(--card-bg); padding: 12px 16px; border-radius: var(--radius); box-shadow: 0 4px 12px rgba(0,0,0,0.2); z-index: 5100; transform: translateY(100px); opacity: 0; transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55); font-weight: 500; display: flex; align-items: center; gap: 12px; min-width: 280px; }
.undo-toast.show { transform: translateY(0); opacity: 1; }
.undo-toast .undo-msg { flex: 1; font-size: 0.9rem; }
.undo-toast button { background: var(--primary); color: white; padding: 6px 14px; font-size: 0.85rem; font-weight: 600; border-radius: 4px; }
.undo-toast button:hover { background: var(--primary-hover); }
.undo-toast .undo-progress { position: absolute; bottom: 0; left: 0; height: 3px; background: var(--primary); border-radius: 0 0 var(--radius) var(--radius); transition: width linear; }

/* Login & Dashboard Styles */
.login-screen { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: var(--bg-color); z-index: 9999; display: flex; justify-content: center; align-items: center; }
.login-card { background: var(--card-bg); padding: 40px; border-radius: var(--radius); box-shadow: 0 10px 25px rgba(0,0,0,0.1); border: 1px solid var(--border-color); width: 100%; max-width: 400px; text-align: center; }

.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; max-width: 600px; margin: 0 auto; padding: 20px; }
.dash-card { background: var(--card-bg); padding: 30px 20px; border-radius: var(--radius); border: 2px solid var(--border-color); cursor: pointer; transition: all 0.3s; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 15px; box-shadow: 0 4px 6px rgba(0,0,0,0.05); }
.dash-card:hover { transform: translateY(-5px); border-color: var(--primary); box-shadow: 0 10px 15px rgba(0,0,0,0.1); }
.dash-card .icon { font-size: 3rem; }
.dash-card h3 { color: var(--text-color); font-size: 1.1rem; margin: 0; }

/* ==========================================================================
   Mobile responsive (Level 1 — make it not break)
   Kicks in below 768px. Strategy:
     - Side panel becomes a horizontal strip pinned to the bottom
     - Main content padding shrinks; right padding no longer reserves side-panel space
     - Meta-data fields stack vertically
     - Modals fill the screen
     - Table stays horizontally scrollable inside its container — that's
       the right behaviour for 14 columns; we don't pretend it fits.
   ========================================================================== */
@media (max-width: 768px) {

    body { padding-bottom: 80px; /* clear the bottom side-panel (60px panel + buffer) */ }

    /* Side panel: pin to bottom, lay out horizontally as a scrollable strip.
       The strip scrolls horizontally because with admin logged in there can
       be 11 buttons, which won't fit on a ~380px phone viewport. */
    .side-panel {
        position: fixed;
        top: auto;
        bottom: 0;
        right: 0;
        left: 0;
        transform: none;
        flex-direction: row;
        justify-content: flex-start;     /* not space-around — that hides overflow */
        align-items: center;
        gap: 8px;
        padding: 8px 12px;
        background: var(--card-bg);
        border-top: 1px solid var(--border-color);
        box-shadow: 0 -2px 8px rgba(0,0,0,0.08);
        z-index: 800;                     /* below modals (1000) so opened modals cover the strip */
        pointer-events: auto;             /* override the desktop hack — strip is solid here */
        overflow-x: auto;                 /* allow horizontal scroll when too many buttons */
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
    }
    .side-panel button {
        /* Full reset — don't inherit any layout from the desktop .side-panel button rule.
           We declare every property that affects sizing, alignment, or hit-testing so the
           visible border and the clickable bounding box are guaranteed to coincide. */
        display: flex;
        align-items: center;
        justify-content: center;          /* not flex-end — center the icon horizontally */
        width: 44px;
        height: 44px;
        min-width: 44px;
        max-width: 44px;
        padding: 0;
        margin: 0;
        border: 2px solid var(--primary);
        border-radius: 22px;
        background-color: var(--card-bg);
        color: var(--text-color);
        box-shadow: none;
        flex-shrink: 0;
        flex-grow: 0;
        flex-basis: 44px;
        cursor: pointer;
        line-height: 1;                   /* prevent inherited line-height from inflating the box */
        vertical-align: middle;
        overflow: hidden;
        position: relative;
        transition: background-color 0.15s ease, color 0.15s ease;
        -webkit-tap-highlight-color: rgba(74, 108, 247, 0.3);
        touch-action: manipulation;
    }
    .side-panel button:hover,
    .side-panel button:active,
    .side-panel button:focus {
        background-color: var(--primary);
        color: white;
        outline: none;
    }
    .side-panel button .text { display: none; }
    .side-panel button .icon {
        display: block;
        font-size: 1.3rem;
        line-height: 1;
        min-width: 0;
        margin: 0;
        text-align: center;
    }

    /* Main content: drop the 90px right padding (no fixed side panel taking that space) */
    .main-content { padding: 1rem; }
    header { padding: 1.5rem 1rem 0.5rem; }
    h2 { font-size: 1.3rem; }

    /* Meta-data: stack vertically */
    .meta-data { padding: 12px; }
    .meta-data-row { min-width: 100%; }

    /* Table: tighten cell padding, shrink min-widths to keep the table scrollable but compact */
    .table-container { font-size: 0.85rem; }
    th, td { padding: 6px 4px; }
    th { font-size: 0.7rem; }
    input, select { padding: 6px; font-size: 0.85rem; }
    .smart-time { width: 65px; font-size: 0.8rem; }

    /* Modals: full-width with margin */
    .modal-content { width: 95%; max-width: 95%; padding: 18px; }
    .modal-content.wide { max-width: 95%; }

    /* Dashboard tiles: single column on phones */
    .dash-grid { grid-template-columns: 1fr; max-width: 100%; gap: 12px; padding: 12px; }
    .dash-card { padding: 20px 16px; }
    .dash-card .icon { font-size: 2rem; }

    /* Wizard: form grid stacks */
    .wiz-form-grid { grid-template-columns: 1fr; }
    .wiz-form-grid .full-width { grid-column: span 1; }
    .wiz-checkbox-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }

    /* Login card: full-width on small screens */
    .login-card { padding: 24px; max-width: 95%; }

    /* Toasts: pull off the bottom edge so they don't overlap the bottom side-panel */
    .toast, .undo-toast { bottom: 80px; right: 10px; left: 10px; }
    .undo-toast { min-width: auto; }

    /* When any modal is open, hide the bottom strip entirely — this prevents
       the side-panel from intercepting taps meant for the modal, and gives the
       modal the full screen height it needs on small viewports. Uses :has()
       which is supported on iOS 15.4+, Chrome 105+, Firefox 121+. Browsers
       without :has() fall back to the z-index layering above (still works,
       just slightly tighter at the bottom). */
    body:has(.modal.show) .side-panel { display: none; }
}
