/* ==========================================================================
   NTA Management - site stylesheet
   Theme follows the system (prefers-color-scheme) unless the user picked one:
   <html data-theme="dark"> or <html data-theme="light"> (accounts.darkmode 1/2)
   ========================================================================== */

:root {
    --bg: #f1f5f9;
    --surface: #ffffff;
    --surface-alt: #f8fafc;
    --text: #0f172a;
    --muted: #64748b;
    --border: #e2e8f0;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-contrast: #ffffff;
    --accent-soft: #dbeafe;
    --topbar-bg: #1e293b;
    --topbar-text: #cbd5e1;
    --topbar-active: #ffffff;
    --ok: #15803d;
    --ok-soft: #dcfce7;
    --warn: #b45309;
    --warn-soft: #fef3c7;
    --danger: #b91c1c;
    --danger-soft: #fee2e2;
    --radius: 8px;
    --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .1);
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* Dark tokens: system dark mode, unless the user forced light */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0f172a;
        --surface: #1e293b;
        --surface-alt: #273449;
        --text: #e2e8f0;
        --muted: #94a3b8;
        --border: #334155;
        --accent: #60a5fa;
        --accent-hover: #93c5fd;
        --accent-contrast: #0f172a;
        --accent-soft: #1e3a5f;
        --topbar-bg: #020617;
        --topbar-text: #94a3b8;
        --topbar-active: #f8fafc;
        --ok: #4ade80;
        --ok-soft: #14532d;
        --warn: #fbbf24;
        --warn-soft: #713f12;
        --danger: #f87171;
        --danger-soft: #7f1d1d;
        --shadow: 0 1px 2px rgba(0, 0, 0, .4);
        color-scheme: dark;
    }
}

/* Dark tokens: user forced dark (keep in sync with the block above) */
:root[data-theme="dark"] {
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-alt: #273449;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --border: #334155;
    --accent: #60a5fa;
    --accent-hover: #93c5fd;
    --accent-contrast: #0f172a;
    --accent-soft: #1e3a5f;
    --topbar-bg: #020617;
    --topbar-text: #94a3b8;
    --topbar-active: #f8fafc;
    --ok: #4ade80;
    --ok-soft: #14532d;
    --warn: #fbbf24;
    --warn-soft: #713f12;
    --danger: #f87171;
    --danger-soft: #7f1d1d;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
}

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

*, *::before, *::after {
    box-sizing: border-box;
}

html {
    color-scheme: light;
}

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
}

a {
    color: var(--accent);
    text-decoration: none;
}

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

h1, h2, h3, h4 {
    line-height: 1.25;
    margin: 1.2em 0 .5em;
}

h2 {
    font-size: 1.5rem;
}

h3 {
    font-size: 1.15rem;
}

h4 {
    font-size: 1rem;
}

.muted {
    color: var(--muted);
}

/* ---------- Layout ---------- */

.container {
    flex: 1;
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 8px 24px 32px;
}

.topbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 16px;
    padding: 0 24px;
    min-height: 56px;
    background: var(--topbar-bg);
    color: var(--topbar-text);
}

.topbar .brand {
    color: var(--topbar-active);
    font-size: 1.1rem;
    font-weight: 700;
    white-space: nowrap;
    text-decoration: none;
}

.mainnav, .usernav {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px;
}

.mainnav {
    flex: 1;
}

.mainnav a, .usernav a {
    color: var(--topbar-text);
    padding: 8px 10px;
    border-radius: 6px;
    text-decoration: none;
    white-space: nowrap;
}

.mainnav a:hover, .usernav a:hover {
    color: var(--topbar-active);
    background: rgba(255, 255, 255, .08);
}

.mainnav a.active, .usernav a.active {
    color: var(--topbar-active);
    background: rgba(255, 255, 255, .14);
}

.usernav .username {
    color: var(--topbar-active);
    font-weight: 600;
    padding-right: 6px;
}

.navtoggle, .navtoggle-label {
    display: none;
}

.site-footer {
    padding: 16px 24px;
    text-align: center;
    color: var(--muted);
    font-size: .85rem;
    border-top: 1px solid var(--border);
}

@media (max-width: 900px) {
    .topbar {
        padding: 8px 16px;
    }

    .navtoggle-label {
        display: block;
        margin-left: auto;
        font-size: 1.5rem;
        line-height: 1;
        padding: 6px 8px;
        cursor: pointer;
        color: var(--topbar-active);
    }

    .mainnav, .usernav {
        display: none;
        flex-basis: 100%;
        flex-direction: column;
        align-items: stretch;
    }

    .navtoggle:checked ~ .mainnav, .navtoggle:checked ~ .usernav {
        display: flex;
    }

    .usernav {
        border-top: 1px solid rgba(255, 255, 255, .1);
        padding-top: 6px;
        margin-bottom: 6px;
    }

    .container {
        padding: 8px 16px 24px;
    }
}

/* ---------- Components ---------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px 20px;
}

.alert {
    margin: 16px 0;
    padding: 12px 16px;
    border-radius: var(--radius);
    background: var(--accent-soft);
    border: 1px solid var(--border);
    color: var(--text);
}

.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: .8rem;
    font-weight: 600;
    white-space: nowrap;
    background: var(--surface-alt);
    color: var(--muted);
}

.badge-ok {
    background: var(--ok-soft);
    color: var(--ok);
}

.badge-warn {
    background: var(--warn-soft);
    color: var(--warn);
}

.badge-danger {
    background: var(--danger-soft);
    color: var(--danger);
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

/* Box detail view */
.box-header {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 8px 0 20px;
}

.box-title {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}

.box-title h3 {
    margin: 0;
    font-size: 1.4rem;
}

.container > .box-title {
    margin: 8px 0 12px;
}

.nowrap {
    white-space: nowrap;
}

/* Full-width DataTables */
table.dataTable {
    width: 100% !important;
}

.box-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 24px;
}

.box-meta .muted {
    display: block;
    font-size: .75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .03em;
}

.box-notes {
    margin: 0;
    padding: 8px 12px;
    border-left: 3px solid var(--warn);
    background: var(--surface-alt);
    border-radius: 4px;
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 16px;
    margin-bottom: 4px;
}

.toolbar h3 {
    margin: 0;
}

.toolbar .tabs {
    margin: 0;
    border-bottom: 0;
}

.toolbar .btn {
    margin-left: auto;
}

td.table-action {
    text-align: center;
    background: var(--surface-alt);
}

/* Dashboard tiles */
.tiles {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 16px;
    margin: 16px 0 8px;
}

.tile {
    display: flex;
    flex-direction: column;
    gap: 4px;
    color: var(--text);
    border-top: 4px solid var(--accent);
    transition: transform .1s ease, box-shadow .1s ease;
}

.tile:hover {
    color: var(--text);
    text-decoration: none;
    transform: translateY(-2px);
}

.tile-ok {
    border-top-color: var(--ok);
}

.tile-warn {
    border-top-color: var(--warn);
}

.tile-danger {
    border-top-color: var(--danger);
}

.tile-label {
    color: var(--muted);
    font-size: .85rem;
    font-weight: 600;
}

.tile-value {
    font-size: 1.9rem;
    font-weight: 700;
    line-height: 1.1;
}

.tile-value small {
    font-size: .9rem;
    font-weight: 500;
    color: var(--muted);
}

.tile-sub {
    color: var(--muted);
    font-size: .85rem;
}

/* Login / logout */
.login-wrap {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 8vh;
}

.login-card {
    width: 100%;
    max-width: 420px;
}

.login-card table, .login-card table tr:nth-child(even) td {
    background: none;
    border: 0;
    box-shadow: none;
    width: 100%;
}

.login-card th, .login-card td {
    border: 0;
    padding: 6px 0;
}

.login-card input[type="text"], .login-card input[type="password"] {
    width: 100%;
}

.login-title {
    margin-top: 0;
    text-align: center;
}

.tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.tabs a {
    padding: 8px 14px;
    color: var(--muted);
    border-bottom: 2px solid transparent;
}

.tabs a:hover {
    color: var(--accent);
    text-decoration: none;
    border-bottom-color: var(--accent);
}

.tabs a.active {
    color: var(--accent);
    font-weight: 600;
    border-bottom-color: var(--accent);
}

.container > .tabs {
    flex-wrap: wrap;
    margin-top: 4px;
}

/* ---------- Tables ---------- */

.table-wrap {
    overflow-x: auto;
    margin: 8px 0 16px;
}

table {
    border-collapse: separate;
    border-spacing: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin: 8px 0 16px;
}

.table-wrap > table {
    margin: 0;
    min-width: 100%;
}

th, td {
    padding: 8px 12px;
    text-align: left;
    vertical-align: middle;
    border-bottom: 1px solid var(--border);
}

th {
    background: var(--surface-alt);
    color: var(--muted);
    font-size: .85rem;
    font-weight: 600;
}

tr:last-child > td, tr:last-child > th {
    border-bottom: 0;
}

tr:first-child > th:first-child {
    border-top-left-radius: var(--radius);
}

tr:first-child > th:last-child {
    border-top-right-radius: var(--radius);
}

/* Nested layout tables (forms inside cells etc.) stay flat */
td table {
    box-shadow: none;
    margin: 0;
}

.thcenter th {
    text-align: center;
}

/* Box status rows */
tr.status-0 > td:first-child {
    box-shadow: inset 4px 0 0 var(--warn);
}

tr.status-1 > td:first-child {
    box-shadow: inset 4px 0 0 var(--danger);
}

tr.status-2 > td:first-child {
    box-shadow: inset 4px 0 0 var(--ok);
}

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

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], input[type="search"], input[type="file"], select, textarea {
    font: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 10px;
    max-width: 100%;
}

input:focus, select:focus, textarea:focus {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
    border-color: var(--accent);
}

input[type="checkbox"], input[type="radio"] {
    accent-color: var(--accent);
    width: 16px;
    height: 16px;
}

button, input[type="submit"], input[type="button"], .btn {
    display: inline-block;
    font: inherit;
    font-weight: 600;
    color: var(--accent-contrast);
    background: var(--accent);
    border: 1px solid var(--accent);
    border-radius: 6px;
    padding: 6px 14px;
    cursor: pointer;
    text-decoration: none;
}

button:hover, input[type="submit"]:hover, input[type="button"]:hover, .btn:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    color: var(--accent-contrast);
    text-decoration: none;
}

.btn-secondary, button.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border-color: var(--border);
}

.btn-secondary:hover, button.btn-secondary:hover {
    background: var(--surface-alt);
    color: var(--text);
    border-color: var(--border);
}

/* ---------- DataTables ---------- */

.dataTables_wrapper {
    margin: 8px 0 16px;
    color: var(--text);
}

table.dataTable {
    border-collapse: separate !important;
    border: 1px solid var(--border);
}

table.dataTable thead th, table.dataTable thead td {
    border-bottom: 1px solid var(--border);
    background-color: var(--surface-alt);
}

table.dataTable tbody tr {
    background-color: var(--surface);
}

table.dataTable.stripe tbody tr.odd, table.dataTable.display tbody tr.odd {
    background-color: var(--surface-alt);
}

table.dataTable.hover tbody tr:hover, table.dataTable.display tbody tr:hover {
    background-color: var(--accent-soft);
}

table.dataTable.order-column tbody tr > .sorting_1,
table.dataTable.order-column.stripe tbody tr.odd > .sorting_1,
table.dataTable.order-column.stripe tbody tr.even > .sorting_1 {
    background-color: transparent;
}

table.dataTable.row-border tbody th, table.dataTable.row-border tbody td,
table.dataTable.display tbody th, table.dataTable.display tbody td {
    border-top: 1px solid var(--border);
}

table.dataTable.no-footer {
    border-bottom: 1px solid var(--border);
}

.sorting, .sorting_asc, .sorting_desc {
    text-align: left;
    background-position-x: left !important;
}

table.dataTable.compact thead th, table.dataTable.compact thead td {
    padding-left: 20px;
}

.dataTables_wrapper .dataTables_length, .dataTables_wrapper .dataTables_filter,
.dataTables_wrapper .dataTables_info, .dataTables_wrapper .dataTables_processing,
.dataTables_wrapper .dataTables_paginate {
    color: var(--muted);
    margin: 8px 0;
}

.dataTables_wrapper .dataTables_filter input {
    margin-left: 6px;
}

.dataTables_wrapper .dataTables_paginate .paginate_button {
    color: var(--text) !important;
    border: 1px solid transparent !important;
    border-radius: 6px;
    background: none !important;
}

.dataTables_wrapper .dataTables_paginate .paginate_button:hover {
    color: var(--accent) !important;
    border-color: var(--border) !important;
    background: var(--surface) !important;
}

.dataTables_wrapper .dataTables_paginate .paginate_button.current,
.dataTables_wrapper .dataTables_paginate .paginate_button.current:hover {
    color: var(--accent-contrast) !important;
    background: var(--accent) !important;
    border-color: var(--accent) !important;
}

.dataTables_wrapper .dataTables_paginate .paginate_button.disabled,
.dataTables_wrapper .dataTables_paginate .paginate_button.disabled:hover {
    color: var(--muted) !important;
    background: none !important;
    border-color: transparent !important;
}

div.dt-buttons {
    margin: 8px 0;
}

div.dt-buttons .dt-button, button.dt-button, a.dt-button {
    font: inherit;
    font-size: .85rem;
    color: var(--text);
    background: var(--surface);
    background-image: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 4px 12px;
    margin-right: 4px;
}

div.dt-buttons .dt-button:hover:not(.disabled), button.dt-button:hover:not(.disabled), a.dt-button:hover:not(.disabled) {
    color: var(--accent);
    background: var(--surface-alt);
    background-image: none;
    border-color: var(--accent);
}

/* ---------- Product search dropdown ---------- */

.results {
    position: absolute;
    z-index: 999;
    width: 250px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.results p {
    margin: 0;
    padding: 7px 10px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
}

.results p:last-child {
    border-bottom: 0;
}

.results p:hover {
    background: var(--accent-soft);
}

/* ---------- Misc ---------- */

.zoom {
    font-size: xxx-large;
    background-color: #000;
    color: #fff;
    letter-spacing: 5px;
}

/* Tooltip container */
.tooltip {
    position: relative;
    display: inline-block;
    border-bottom: 1px dotted var(--muted);
    cursor: help;
}

/* Tooltip text */
.tooltip .tooltiptext {
    display: none;
    width: auto;
    min-width: 160px;
    max-width: 320px;
    background-color: #0f172a;
    color: #f8fafc;
    text-align: center;
    font-size: .85rem;
    font-weight: 400;
    padding: 6px 10px;
    border-radius: 6px;
    box-shadow: var(--shadow);
    position: absolute;
    z-index: 10;
}

.tooltip-bottom {
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
}

.tooltip-top {
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
}

.tooltip-right {
    top: -5px;
    left: 105%;
}

.tooltip-left {
    top: -5px;
    right: 105%;
}

/* Show/hide the tooltip text when you mouse over the tooltip container */
.tooltip:hover .tooltiptext {
    display: block;
}

.tooltip .tooltiptext:hover {
    display: none;
}

/* ---------- Print ---------- */

@media print {
    .topbar, .site-footer, .dt-buttons, .dataTables_filter, .dataTables_paginate, .dataTables_length {
        display: none !important;
    }

    body {
        background: #fff;
        color: #000;
    }

    table {
        box-shadow: none;
    }
}
