/* ==========================================================================
   TimeKeep design system
   Modern, restrained UI: one blue accent, neutral grays, soft elevation,
   smooth (150-300ms) transitions, accessible focus + contrast. No neon,
   no harsh animation, no gradients. Icons are SVG (Lucide).
   ========================================================================== */

/* Self-hosted Open Sans (latin subset) */
@font-face { font-family: "Open Sans"; font-style: normal; font-weight: 400; font-display: swap; src: url("/assets/fonts/open-sans-400.woff2") format("woff2"); }
@font-face { font-family: "Open Sans"; font-style: normal; font-weight: 500; font-display: swap; src: url("/assets/fonts/open-sans-500.woff2") format("woff2"); }
@font-face { font-family: "Open Sans"; font-style: normal; font-weight: 600; font-display: swap; src: url("/assets/fonts/open-sans-600.woff2") format("woff2"); }
@font-face { font-family: "Open Sans"; font-style: normal; font-weight: 700; font-display: swap; src: url("/assets/fonts/open-sans-700.woff2") format("woff2"); }

:root {
    /* Neutrals */
    --ink: #111827;
    --ink-soft: #374151;
    --muted: #6b7280;
    --line: #e5e7eb;
    --line-strong: #d1d5db;
    --bg: #f3f5f9;
    --surface: #ffffff;
    --surface-2: #f9fafb;

    /* Accent + status */
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-weak: #eff4ff;
    --green: #15803d;
    --green-bg: #dcfce7;
    --red: #dc2626;
    --red-bg: #fee2e2;
    --amber: #b45309;
    --amber-bg: #fef3c7;
    --teal: #0f766e;
    --teal-bg: #cffafe;

    /* Shape + depth */
    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;
    --pill: 999px;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
    --shadow: 0 1px 3px rgba(16, 24, 40, .10), 0 1px 2px rgba(16, 24, 40, .06);
    --shadow-md: 0 8px 24px rgba(16, 24, 40, .10);
    --ring: 0 0 0 3px rgba(37, 99, 235, .35);
    --t: 160ms ease;

    /* Surfaces that differ by theme */
    --topbar-bg: rgba(255, 255, 255, .9);
    --scheme: light;
}

/* ---- Dark theme ---- */
:root[data-theme="dark"] {
    --ink: #e5e7eb;
    --ink-soft: #cbd5e1;
    --muted: #94a3b8;
    --line: #2b3648;
    --line-strong: #3b4a61;
    --bg: #0f172a;
    --surface: #1b2536;
    --surface-2: #232f44;

    --accent: #3b82f6;
    --accent-hover: #60a5fa;
    --accent-weak: #1d2c47;
    --green: #4ade80;
    --green-bg: #14532d;
    --red: #f87171;
    --red-bg: #7f1d1d;
    --amber: #fbbf24;
    --amber-bg: #713f12;
    --teal: #2dd4bf;
    --teal-bg: #134e4a;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow: 0 1px 3px rgba(0, 0, 0, .5), 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, .55);
    --ring: 0 0 0 3px rgba(96, 165, 250, .45);
    --topbar-bg: rgba(15, 23, 42, .85);
    --scheme: dark;
}

/* Let native form controls / scrollbars follow the theme */
:root { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: "Open Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--ink);
    background: var(--bg);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

a { color: var(--accent-hover); text-decoration: none; transition: color var(--t); }
a:hover { color: var(--accent); text-decoration: underline; }

/* Visible keyboard focus everywhere */
:focus-visible {
    outline: none;
    box-shadow: var(--ring);
    border-radius: var(--radius-sm);
}

/* Lucide icons render as <svg class="lucide">; size to surrounding text. */
.lucide, [data-lucide] {
    width: 1em; height: 1em;
    display: inline-block; vertical-align: -0.125em;
    stroke-width: 2;
    flex-shrink: 0;
}

/* ---- Top bar ---- */
.topbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; gap: 1.5rem;
    background: var(--topbar-bg);
    backdrop-filter: saturate(180%) blur(8px);
    border-bottom: 1px solid var(--line);
    padding: .8rem 1.5rem;
}
.brand { font-weight: 700; font-size: 1.15rem; display: inline-flex; align-items: center; gap: .5rem; letter-spacing: -0.01em; }
.brand .lucide { color: var(--accent); width: 1.2em; height: 1.2em; }
.mainnav { display: flex; gap: .35rem; flex: 1; }
.mainnav a {
    color: var(--ink-soft); font-weight: 500; font-size: .95rem;
    display: inline-flex; align-items: center; gap: .45rem;
    padding: .45rem .7rem; border-radius: var(--radius-sm);
    transition: background var(--t), color var(--t);
}
.mainnav a:hover { background: var(--accent-weak); color: var(--accent-hover); text-decoration: none; }
.mainnav a .lucide { color: var(--muted); transition: color var(--t); }
.mainnav a:hover .lucide { color: var(--accent); }
.whoami { color: var(--muted); font-size: .9rem; font-weight: 500; display: inline-flex; align-items: center; gap: .4rem; }

/* Icon-only button (theme toggle) */
.icon-btn {
    position: relative;
    display: inline-flex; align-items: center; justify-content: center;
    width: 2.1rem; height: 2.1rem; padding: 0;
    border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
    background: var(--surface); color: var(--ink-soft); cursor: pointer;
    text-decoration: none;
    transition: background var(--t), color var(--t), border-color var(--t);
}
.icon-btn .lucide { width: 1.15em; height: 1.15em; }
.icon-btn:hover { background: var(--accent-weak); color: var(--accent-hover); border-color: var(--accent); text-decoration: none; }
.theme-toggle .icon-to-light { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-to-dark { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-to-light { display: inline-block; }

/* Instant hover tooltip for the top-bar icon buttons */
.icon-btn::after {
    position: absolute; top: calc(100% + 6px); right: 0;
    white-space: nowrap; background: var(--ink); color: var(--surface);
    padding: .3rem .5rem; border-radius: 6px; font-size: .75rem; font-weight: 500;
    opacity: 0; pointer-events: none; transition: opacity var(--t); z-index: 30;
}
.icon-btn:hover::after, .icon-btn:focus-visible::after { opacity: 1; }
.icon-btn[data-tooltip]::after { content: attr(data-tooltip); }
.theme-toggle::after { content: "Dark mode"; }
:root[data-theme="dark"] .theme-toggle::after { content: "Light mode"; }

/* ---- Layout ---- */
.container { max-width: 1040px; margin: 1.75rem auto; padding: 0 1.5rem; }
h1 { font-size: 1.7rem; font-weight: 700; letter-spacing: -0.02em; margin: 0 0 1rem; }
h2 { font-size: 1.2rem; font-weight: 600; letter-spacing: -0.01em; }
h3 { font-size: 1rem; font-weight: 600; }
.muted { color: var(--muted); }

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 1.5rem;
    margin: 1.25rem 0;
}

/* ---- Flash messages ---- */
.flash {
    padding: .7rem 1rem; border-radius: var(--radius-sm); margin: .6rem 0;
    font-size: .95rem; border: 1px solid color-mix(in srgb, currentColor 28%, transparent);
}
.flash-info { background: var(--accent-weak); color: var(--accent-hover); }
.flash-success { background: var(--green-bg); color: var(--green); }
.flash-error { background: var(--red-bg); color: var(--red); }

/* ---- Buttons ---- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
    padding: .55rem 1rem; border-radius: var(--radius-sm);
    border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
    text-decoration: none; cursor: pointer; font-size: .95rem; font-weight: 600; font-family: inherit;
    line-height: 1.2;
    transition: background var(--t), border-color var(--t), box-shadow var(--t), transform var(--t), filter var(--t);
}
.btn:hover { background: var(--surface-2); border-color: var(--muted); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-danger:hover { background: #b91c1c; border-color: #b91c1c; filter: none; }
.linkbtn { background: none; border: none; color: var(--accent-hover); cursor: pointer; padding: 0; font: inherit; }
.inline { display: inline; }

/* ---- Login / setup ---- */
.login-card {
    max-width: 400px; margin: 4rem auto; background: var(--surface);
    border: 1px solid var(--line); border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md); padding: 2rem;
}
.login-card label { display: block; margin: .9rem 0; font-size: .9rem; font-weight: 500; color: var(--ink-soft); }
.login-card input, .login-card select {
    width: 100%; padding: .65rem .75rem; border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm); font-size: 1rem; font-family: inherit; margin-top: .3rem;
    transition: border-color var(--t), box-shadow var(--t);
}
.login-card .btn { width: 100%; margin-top: .75rem; }
.login-alt { margin-top: 1.1rem; text-align: center; font-size: .9rem; }
.login-alt a { color: var(--muted); display: inline-flex; align-items: center; gap: .35rem; }
.login-alt a:hover { color: var(--accent-hover); text-decoration: none; }
.setup-card { max-width: 480px; }
.setup-card h2 { font-size: .8rem; margin: 1.5rem 0 .25rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.setup-card select { width: 100%; padding: .65rem .75rem; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); font-size: 1rem; }
.tabs { display: flex; gap: .4rem; margin-bottom: 1.25rem; background: var(--surface-2); padding: .3rem; border-radius: var(--radius-sm); }
.tab { flex: 1; text-align: center; padding: .55rem; border-radius: 6px; text-decoration: none;
    color: var(--ink-soft); font-weight: 600; font-size: .9rem; transition: background var(--t), color var(--t); }
.tab:hover { color: var(--accent-hover); text-decoration: none; }
.tab.active { background: var(--surface); color: var(--accent); box-shadow: var(--shadow-sm); }

/* ---- Clock panel ---- */
.clock-panel {
    text-align: center; background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius-lg); box-shadow: var(--shadow); padding: 2.5rem 1.5rem;
}
.clock-panel h1 { margin-bottom: .25rem; }
.bigclock { font-size: 3.5rem; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.clock-date { color: var(--muted); margin-bottom: 1.25rem; }
.state-badge {
    display: inline-flex; align-items: center; gap: .4rem;
    padding: .4rem 1rem; border-radius: var(--pill); font-weight: 600; font-size: .9rem;
}
.state-out { background: var(--red-bg); color: var(--red); }
.state-in { background: var(--green-bg); color: var(--green); }
.state-lunch { background: var(--amber-bg); color: var(--amber); }
.state-break { background: var(--teal-bg); color: var(--teal); }
.clock-actions { display: flex; gap: 1rem; justify-content: center; flex-wrap: wrap; margin: 1.75rem 0; }
.clock-actions form { margin: 0; }
.btn-big { font-size: 1.2rem; padding: 1rem 1.75rem; border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.btn-in { background: var(--green); border-color: var(--green); color: #fff; }
.btn-in:hover { background: #166534; border-color: #166534; }
.btn-out { background: var(--red); border-color: var(--red); color: #fff; }
.btn-out:hover { background: #b91c1c; border-color: #b91c1c; }
.btn-lunch { background: var(--amber); border-color: var(--amber); color: #fff; }
.btn-lunch:hover { background: #92400e; border-color: #92400e; }
.btn-break { background: var(--teal); border-color: var(--teal); color: #fff; }
.btn-break:hover { background: #115e59; border-color: #115e59; }
.today-summary { font-size: 1.05rem; color: var(--ink-soft); }

/* ---- Forms ---- */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1.1rem; }
.form-grid label { display: flex; flex-direction: column; gap: .35rem; font-size: .85rem; font-weight: 500; color: var(--ink-soft); }
.form-grid input, .form-grid select {
    padding: .55rem .7rem; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
    font-size: 1rem; font-family: inherit; color: var(--ink); background: var(--surface);
    transition: border-color var(--t), box-shadow var(--t);
}
.form-grid input:focus, .form-grid select:focus,
.login-card input:focus, .login-card select:focus,
.setup-card select:focus, .custom-range input:focus, .custom-range select:focus {
    outline: none; border-color: var(--accent); box-shadow: var(--ring);
}
.form-grid .full, .form-actions.full { grid-column: 1 / -1; }
.form-grid label.check { flex-direction: row; align-items: center; gap: .5rem; font-size: .95rem; color: var(--ink); }
.form-grid label.check input { width: auto; }
.form-actions { margin-top: 1.25rem; display: flex; gap: .6rem; }
.danger-form { margin-top: 1.25rem; }

/* ---- Tables ---- */
table.grid, table.timecard {
    width: 100%; border-collapse: collapse; margin: .5rem 0;
    font-variant-numeric: tabular-nums;
}
table.grid th, table.timecard th {
    text-align: left; font-size: .72rem; color: var(--muted); font-weight: 600;
    background: var(--surface-2);
    border-bottom: 1px solid var(--line); padding: .6rem .6rem;
    text-transform: uppercase; letter-spacing: .04em; white-space: nowrap;
}
table.grid td, table.timecard td { padding: .6rem .6rem; border-bottom: 1px solid var(--line); font-size: .92rem; }
table.timecard tbody tr { transition: background var(--t); }
table.timecard tbody tr:hover { background: var(--accent-weak); }
table.timecard td.total { font-weight: 700; }
table.timecard .totals-row td { font-weight: 700; background: var(--surface-2);
    border-top: 2px solid var(--line-strong); border-bottom: none; }
table.timecard .totals-row:hover { background: var(--surface-2); }
table.timecard td.actions a { font-size: .85rem; display: inline-flex; align-items: center; gap: .25rem; }
table.timecard td.pay { font-weight: 700; color: var(--green); white-space: nowrap; }
.date { color: var(--ink); font-weight: 600; white-space: nowrap; }

/* Lunch/break detail rows (collapsible) */
.row-toggle {
    background: none; border: none; cursor: pointer; padding: 0 .25rem 0 0;
    color: var(--muted); line-height: 1; vertical-align: middle;
}
.row-toggle:hover { color: var(--accent); }
.row-toggle .lucide { transition: transform var(--t); }
.row-toggle[aria-expanded="true"] .lucide { transform: rotate(90deg); }
table.timecard tr.detail-row td { background: var(--surface-2); color: var(--muted); font-size: .85rem; }
table.timecard tr.detail-row:hover td { background: var(--surface-2); }
table.timecard tr.detail-row .detail-label { padding-left: 1.7rem; font-style: italic; }

/* ---- Lunch/break interval editor ---- */
.intervals-fieldset { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 1rem 1.1rem; background: var(--surface-2); }
.intervals-fieldset legend { font-size: .8rem; font-weight: 600; color: var(--muted); padding: 0 .4rem; text-transform: uppercase; letter-spacing: .03em; }
.interval-row { display: flex; gap: 1rem; margin-bottom: .6rem; }
.interval-row label { flex: 1; display: flex; flex-direction: column; gap: .3rem; font-size: .82rem; font-weight: 500; color: var(--ink-soft); }
.interval-row input { padding: .5rem .7rem; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); font-family: inherit; font-size: .95rem; }
.interval-row input:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }

/* ---- Report ---- */
.report-emp {
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: var(--shadow-sm); padding: 1.25rem 1.5rem; margin: 1.25rem 0;
}
.report-emp h2 { display: flex; align-items: baseline; gap: .6rem; flex-wrap: wrap; margin-top: 0; }
.report-emp h2 .muted { font-size: .9rem; font-weight: 500; }
.range-bar { margin: .5rem 0; color: var(--ink); }
.range-label { color: var(--muted); margin-bottom: .5rem; font-size: .9rem; }

/* ---- Date picker ---- */
.datepicker {
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: var(--shadow-sm); padding: 1rem 1.25rem; margin: .5rem 0 1.25rem;
}
.presets { display: flex; flex-wrap: wrap; gap: .45rem; margin-bottom: .8rem; }
.chip {
    padding: .4rem .85rem; border-radius: var(--pill); border: 1px solid var(--line-strong);
    background: var(--surface); color: var(--ink-soft); cursor: pointer; font-size: .9rem; font-weight: 500;
    font-family: inherit; transition: background var(--t), color var(--t), border-color var(--t);
}
.chip:hover { background: var(--accent-weak); border-color: var(--accent); color: var(--accent-hover); }
.chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.custom-range { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; font-size: .9rem; }
.custom-range input, .custom-range select {
    padding: .45rem .6rem; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
    font-family: inherit; font-size: .9rem;
}

/* Card header row: employee name on the left, hours-format toggle on the right */
.report-emp-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: .5rem; }
.report-emp-head h2 { margin: 0; }

/* Per-card timecard controls (hours toggle + Save PDF) */
.card-controls { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }

/* Hours-format toggle */
.fmt-toggle { display: flex; align-items: center; gap: .5rem; margin: 0; }
.fmt-toggle-label { font-size: .85rem; color: var(--muted); font-weight: 500; }
.fmt-toggle .chip { display: inline-flex; align-items: center; gap: .4rem; }

.footer { text-align: center; color: var(--muted); padding: 2.5rem 1rem; font-size: .85rem; }

/* ---- Responsive ---- */
@media (max-width: 768px) {
    .topbar { flex-wrap: wrap; gap: .75rem; padding: .7rem 1rem; }
    .mainnav { order: 3; width: 100%; flex-wrap: wrap; }
    .container { margin: 1.25rem auto; padding: 0 1rem; }
    .bigclock { font-size: 2.75rem; }
    table.grid, table.timecard { display: block; overflow-x: auto; white-space: nowrap; }
}
@media (max-width: 600px) {
    .form-grid { grid-template-columns: 1fr; }
    .interval-row { flex-direction: column; gap: .5rem; }
    .btn-big { width: 100%; }
    .clock-actions { flex-direction: column; }
}

/* ---- Print: clean timecard PDF ---- */
@media print {
    /* Force a light palette regardless of the on-screen theme. */
    :root, :root[data-theme="dark"] {
        --ink: #000; --ink-soft: #222; --muted: #555;
        --line: #999; --line-strong: #777;
        --bg: #fff; --surface: #fff; --surface-2: #fff;
        --accent: #000; --accent-hover: #000; --accent-weak: #fff;
        --green: #000; --teal: #000; --red: #000;
    }
    body { background: #fff; color: #000; }

    /* Hide app chrome and interactive-only controls. */
    .topbar, .footer, .datepicker, .card-controls, .range-bar,
    .row-toggle, .actions, .flash { display: none !important; }
    table.timecard thead th:empty { display: none; }

    .container { max-width: none; margin: 0; padding: 0; }
    .report-emp { border: none; box-shadow: none; padding: 0; margin: 0 0 1rem; }
    .report-emp + .report-emp { break-before: page; }
    h1 { font-size: 1.2rem; }
    .report-emp h2 { font-size: 1.05rem; }

    /* Always show lunch/break detail in the printout, even if collapsed. */
    table.timecard tr.detail-row[hidden] { display: table-row !important; }

    /* Crisp, bordered table that repeats its header across pages. */
    table.timecard { font-size: 11px; }
    table.timecard thead { display: table-header-group; }
    table.timecard th, table.timecard td {
        border: 1px solid #999 !important; background: #fff !important;
        color: #000 !important; padding: 3px 6px;
    }
    table.timecard tr, table.timecard td.total, table.timecard td.pay { break-inside: avoid; }
    table.timecard .totals-row td { border-top: 2px solid #000 !important; font-weight: 700; }
}

/* ---- Reduced motion ---- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .001ms !important;
        scroll-behavior: auto !important;
    }
}
