:root {
    --bg: #f5f7fb;
    --surface: #ffffff;
    --surface-soft: #f6f7f7;
    --border: #d7d9dc;
    --border-strong: #bfc4c9;
    --ink: #2f3337;
    --muted: #70777d;
    --nav: #ffffff;
    --nav-soft: #f1f2f3;
    --accent: #6f777d;
    --accent-dark: #4f575d;
    --accent-soft: #eceeef;
    --teal: #44786f;
    --teal-soft: #edf5f3;
    --amber: #9a7a35;
    --amber-soft: #f8f2e5;
    --ok: #15803d;
    --ok-soft: #e8f7ee;
    --warn: #a16207;
    --warn-soft: #fff7e6;
    --err: #b42318;
    --err-soft: #fdeceb;
    --shadow: 0 14px 30px rgba(47, 51, 55, 0.09);
    --radius: 8px;
}

* { box-sizing: border-box; }

html { min-width: 320px; }

body {
    margin: 0;
    font-family: Inter, "Segoe UI", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--ink);
    font-size: 14px;
    line-height: 1.45;
}

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

a:hover { text-decoration: underline; }

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    background: rgba(255, 255, 255, 0.96);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(14px);
}

.topbar-inner {
    max-width: 1180px;
    margin: 0 auto;
    padding: 12px 24px;
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 24px;
    align-items: center;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-width: max-content;
    font-weight: 700;
    color: var(--ink);
}

.brand:hover { text-decoration: none; }

.brand-logo {
    width: 82px;
    height: 48px;
    display: block;
    object-fit: contain;
}

.brand-title {
    padding-left: 10px;
    border-left: 1px solid var(--border);
    color: var(--accent-dark);
    font-weight: 800;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 6px;
}

.nav-links a {
    padding: 7px 10px;
    border-radius: 6px;
    color: #525960;
    font-weight: 600;
}

.nav-links a:hover {
    background: var(--nav-soft);
    color: var(--ink);
    text-decoration: none;
}

.nav-links a.active {
    background: var(--accent-dark);
    color: #ffffff;
}

.account-menu {
    display: flex;
    align-items: center;
    gap: 14px;
}

.whoami {
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--muted);
}

.account-menu a {
    color: var(--accent-dark);
    font-weight: 700;
}

.account-menu a:hover {
    color: var(--ink);
}

.logout-button,
.download-button {
    min-height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 7px;
    padding: 7px 12px;
    font-size: 13px;
    font-weight: 800;
    line-height: 1;
    white-space: nowrap;
    text-decoration: none;
}

.logout-button {
    border: 1px solid var(--border-strong);
    background: #ffffff;
    color: var(--accent-dark);
}

.logout-button:hover {
    background: var(--surface-soft);
    color: var(--ink);
    text-decoration: none;
}

.download-button {
    border: 1px solid var(--accent-dark);
    background: var(--accent-dark);
    color: #ffffff;
}

.download-button:hover {
    background: var(--ink);
    border-color: var(--ink);
    color: #ffffff;
    text-decoration: none;
}

.container {
    max-width: 1180px;
    margin: 0 auto;
    padding: 28px 24px 56px;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 18px;
    margin: 2px 0 20px;
    background: #ffffff;
    border-left: 4px solid var(--accent);
}

.page-header h1,
.auth-card h1 {
    margin: 0;
    font-size: 30px;
    line-height: 1.1;
    letter-spacing: 0;
}

.eyebrow {
    margin: 0 0 6px;
    color: var(--teal);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

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

.accent-card {
    position: relative;
    overflow: hidden;
}

.accent-card::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: 4px;
    background: var(--accent);
}

.accent-card-blue::before { background: var(--accent); }
.accent-card-teal::before { background: var(--teal); }
.accent-card-amber::before { background: var(--amber); }

.section-card {
    padding: 24px;
    margin-bottom: 20px;
}

.compact-card {
    padding: 18px;
}

.compact-card .section-heading {
    margin-bottom: 14px;
}

.compact-card .form-stack {
    gap: 14px;
}

.compact-card .form-section {
    gap: 10px;
}

.admin-user-form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 22px;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
}

.full-width-button {
    width: 100%;
}

.section-heading {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.section-heading h2,
.card h2 {
    margin: 0;
    color: var(--ink);
    font-size: 19px;
    font-weight: 900;
    line-height: 1.25;
    letter-spacing: 0;
}

.section-heading p { margin: 4px 0 0; }

.auth-shell {
    min-height: calc(100vh - 56px);
    display: grid;
    place-items: center;
    padding: 36px 0;
}

.auth-card {
    width: min(100%, 420px);
    padding: 28px;
}

.auth-brand {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 22px;
}

.auth-logo {
    width: 112px;
    height: 66px;
    display: block;
    object-fit: contain;
}

form { margin: 0; }

.form-stack {
    display: grid;
    gap: 18px;
}

.form-stack > button,
.form-stack > .primary,
.form-stack > .flex {
    margin-top: 2px;
}

.form-section {
    display: grid;
    gap: 12px;
}

.form-section-title {
    padding-bottom: 7px;
    border-bottom: 1px solid var(--border);
    color: var(--accent-dark);
    font-size: 12px;
    font-weight: 900;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

label {
    display: block;
    margin-bottom: 0;
    color: #2f3949;
    font-size: 13px;
    font-weight: 700;
}

label input,
label select,
label textarea,
textarea {
    display: block;
    width: 100%;
    margin-top: 7px;
    padding: 10px 11px;
    border: 1px solid var(--border-strong);
    border-radius: 7px;
    background: #fff;
    color: var(--ink);
    font: inherit;
    font-weight: 500;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

label input:focus,
label select:focus,
label textarea:focus,
textarea:focus {
    outline: 0;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(36, 95, 168, 0.16);
}

textarea {
    min-height: 124px;
    resize: vertical;
}

label.checkbox {
    display: flex;
    align-items: center;
    gap: 9px;
}

label.checkbox input {
    width: auto;
    margin: 0;
}

.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
}

.settings-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
}

.settings-panel-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
}

.span-2 { grid-column: span 2; }

button.primary {
    min-height: 40px;
    max-width: 100%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--accent-dark);
    color: #fff;
    border: 1px solid var(--accent-dark);
    border-radius: 7px;
    padding: 9px 16px;
    font: inherit;
    font-weight: 800;
    cursor: pointer;
}

button.primary:hover {
    background: var(--ink);
}
button.primary:disabled { opacity: 0.65; cursor: wait; }

button.secondary-button {
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    color: var(--accent);
    border: 1px solid var(--border-strong);
    border-radius: 7px;
    padding: 9px 14px;
    font: inherit;
    font-weight: 800;
    cursor: pointer;
}

button.secondary-button:hover {
    background: var(--accent-soft);
    border-color: #a9c3e4;
}

button.compact-action {
    min-height: 30px;
    padding: 6px 10px;
    font-size: 12px;
}

.primary-link {
    display: inline-flex;
    align-items: center;
    min-height: 36px;
    padding: 8px 12px;
    border-radius: 7px;
    background: var(--accent-dark);
    color: #fff;
    font-weight: 800;
}

.primary-link:hover {
    background: var(--ink);
    text-decoration: none;
}

.secondary-link {
    color: var(--muted);
    font-weight: 700;
}

button.icon-button {
    width: 30px;
    height: 30px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 6px;
    color: var(--accent);
    cursor: pointer;
}

button.icon-button:hover {
    background: var(--err-soft);
    border-color: #f5c7c3;
}

button.icon-button.danger { color: var(--err); }

button.icon-button svg {
    width: 17px;
    height: 17px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.muted {
    color: var(--muted);
    font-size: 13px;
    font-weight: 500;
}

.field-note {
    display: block;
    margin-top: 6px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 500;
}

.label-row {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.info-tip {
    position: relative;
    display: inline-flex;
    width: 16px;
    height: 16px;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    cursor: pointer;
    vertical-align: text-bottom;
}

.info-tip:hover,
.info-tip:focus {
    color: var(--accent-dark);
    outline: none;
}

.info-tip:focus {
    box-shadow: 0 0 0 3px rgba(79, 87, 93, 0.16);
    border-radius: 50%;
}

.info-tip svg {
    width: 16px;
    height: 16px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.info-tip-content {
    position: absolute;
    z-index: 20;
    top: 24px;
    left: 50%;
    width: 260px;
    transform: translateX(-50%);
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #ffffff;
    box-shadow: var(--shadow);
    color: var(--ink);
    font-size: 12px;
    font-weight: 600;
    line-height: 1.4;
    text-transform: none;
    display: none;
}

.info-tip:hover .info-tip-content,
.info-tip:focus .info-tip-content {
    display: block;
}

code {
    padding: 2px 5px;
    border-radius: 5px;
    background: var(--surface-soft);
    color: #3a4556;
}

.flash {
    padding: 11px 14px;
    border: 1px solid transparent;
    border-radius: 8px;
    margin-bottom: 18px;
    font-weight: 700;
}

.flash-info {
    background: var(--accent-soft);
    border-color: #c8dcf3;
    color: var(--accent-dark);
}

.flash-error {
    background: var(--err-soft);
    border-color: #f5c7c3;
    color: var(--err);
}

.flash-warning {
    background: var(--warn-soft);
    border-color: #f3d28d;
    color: var(--warn);
}

.flash-success {
    background: var(--ok-soft);
    border-color: #c7ead8;
    color: var(--ok);
}

.warning-note {
    margin-top: 4px;
    color: var(--warn);
    font-size: 12px;
    font-weight: 700;
}

.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

.history-filters {
    display: grid;
    grid-template-columns: minmax(220px, 1.4fr) minmax(150px, 1fr) minmax(150px, 1fr) auto;
    gap: 12px;
    align-items: end;
    padding: 14px;
    margin-bottom: 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-soft);
}

.history-filters label {
    margin-bottom: 0;
}

.filter-actions {
    min-height: 40px;
    display: flex;
    align-items: center;
    gap: 12px;
}

table.job-table {
    width: 100%;
    min-width: 720px;
    border-collapse: collapse;
    font-size: 13px;
}

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

table.job-table th {
    background: #eef3f8;
    color: #334155;
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

table.job-table tbody tr:last-child td { border-bottom: 0; }
table.job-table tbody tr:hover { background: #f8fbff; }

.status {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 800;
    text-transform: capitalize;
}

.status-queued { background: #eef2f7; color: #475569; }
.status-running { background: #e8f2ff; color: var(--accent-dark); }
.status-complete { background: var(--ok-soft); color: var(--ok); }
.status-failed { background: var(--err-soft); color: var(--err); }

.settings-tab-button[aria-selected="true"] {
    background: var(--accent-dark);
    color: #ffffff;
    box-shadow: 0 8px 18px rgba(47, 51, 55, 0.16);
}

.job-actions {
    display: flex;
    gap: 10px;
    align-items: center;
    justify-content: flex-end;
    white-space: nowrap;
}

.job-actions form { margin: 0; }

.user-actions {
    min-height: 30px;
}

.current-user-note {
    display: inline-flex;
    align-items: center;
    min-height: 30px;
}

.status-line {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.status-message {
    margin: 0 0 18px;
    font-size: 16px;
    font-weight: 700;
    color: #334155;
}

.status-actions {
    margin-bottom: 16px;
}

@media (max-width: 760px) {
    .topbar-inner {
        grid-template-columns: 1fr;
        gap: 10px;
        padding: 12px 18px;
    }

    .nav-links,
    .account-menu {
        flex-wrap: wrap;
    }

    .container {
        padding: 22px 16px 40px;
    }

    .page-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .page-header h1,
    .auth-card h1 {
        font-size: 25px;
    }

    .section-card,
    .auth-card {
        padding: 18px;
    }

    .grid-2,
    .grid-3,
    .settings-grid,
    .settings-panel-grid,
    .admin-user-form-grid,
    .history-filters {
        grid-template-columns: 1fr;
    }

    .form-actions {
        justify-content: flex-start;
    }

    .span-2 { grid-column: auto; }

    .filter-actions {
        justify-content: flex-start;
    }
}
