:root {
    --bg: #07101f;
    --surface: #0d1a2f;
    --surface-strong: #12233d;
    --surface-sticky: #111f38;
    --border: rgba(148, 163, 184, 0.22);
    --text: #eaf2ff;
    --muted: #99aac1;
    --cyan: #22d3ee;
    --teal: #2dd4bf;
    --danger: #fb7185;
    --focus: #67e8f9;
    --shadow: 0 22px 70px rgba(0, 0, 0, 0.34);
}

* { box-sizing: border-box; }

html {
    min-width: 320px;
    background: var(--bg);
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--text);
    background:
        radial-gradient(circle at 14% 6%, rgba(34, 211, 238, 0.12), transparent 28rem),
        radial-gradient(circle at 88% 10%, rgba(99, 102, 241, 0.13), transparent 32rem),
        var(--bg);
    font: 15px/1.55 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, textarea { font: inherit; }
button { min-height: 44px; }

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
summary:focus-visible,
.matrix-scroll:focus-visible,
.target-table-scroll:focus-visible,
.skip-link:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 3px;
}

.skip-link {
    position: fixed;
    z-index: 100;
    left: 16px;
    top: -80px;
    padding: 10px 14px;
    border-radius: 10px;
    color: #04111f;
    background: var(--focus);
    font-weight: 800;
}

.skip-link:focus { top: 16px; }

.login-shell[hidden],
.dashboard-shell[hidden] {
    display: none !important;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.login-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 28px 18px;
}

.login-panel {
    width: min(100%, 460px);
    padding: clamp(28px, 6vw, 44px);
    border: 1px solid var(--border);
    border-radius: 28px;
    background: linear-gradient(155deg, rgba(18, 35, 61, 0.97), rgba(9, 21, 40, 0.98));
    box-shadow: var(--shadow);
}

.brand-mark {
    width: 52px;
    height: 52px;
    display: grid;
    place-items: center;
    margin-bottom: 24px;
    border-radius: 16px;
    color: #03131d;
    background: linear-gradient(145deg, var(--cyan), #8b5cf6);
    font-size: 24px;
    font-weight: 900;
}

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

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 10px; font-size: clamp(28px, 5vw, 42px); line-height: 1.15; }
h2 { margin-bottom: 4px; font-size: clamp(20px, 3vw, 28px); }
.login-intro, .portal-header p, .matrix-heading p, footer { color: var(--muted); }

.login-form {
    display: grid;
    gap: 10px;
    margin-top: 30px;
}

.login-form label { margin-top: 8px; font-weight: 750; }
.login-form input, .date-control input {
    width: 100%;
    min-height: 48px;
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--text);
    background: rgba(4, 12, 25, 0.72);
    padding: 0 14px;
}

.login-form button {
    margin-top: 12px;
    border: 0;
    border-radius: 12px;
    color: #02131c;
    background: linear-gradient(135deg, var(--cyan), var(--teal));
    font-weight: 850;
    cursor: pointer;
}

.login-form button:disabled { opacity: 0.65; cursor: wait; }
.form-message { min-height: 24px; margin: 4px 0 0; color: var(--danger); }
.security-note { margin: 18px 0 0; color: var(--muted); font-size: 13px; }

.dashboard-shell {
    width: min(100%, 1900px);
    margin: 0 auto;
    padding: clamp(20px, 3vw, 42px);
}

.portal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 28px;
}

.portal-header h1 { margin-bottom: 6px; }
.portal-header p { margin-bottom: 0; }
.account-panel { display: flex; align-items: center; gap: 12px; }
.account-panel span { color: var(--muted); white-space: nowrap; }

.button {
    border: 1px solid var(--border);
    border-radius: 11px;
    padding: 0 15px;
    color: var(--text);
    cursor: pointer;
}

.button:disabled { opacity: 0.5; cursor: not-allowed; }
.button-primary { border-color: transparent; color: #03131d; background: linear-gradient(135deg, var(--cyan), #8b5cf6); font-weight: 800; }
.button-muted { background: rgba(18, 35, 61, 0.72); }
.button-danger { border-color: rgba(251, 113, 133, 0.5); color: #ffe4e6; background: rgba(159, 18, 57, 0.34); font-weight: 800; }

.summary-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.summary-grid article {
    min-height: 104px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    padding: 18px;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: linear-gradient(145deg, rgba(18, 35, 61, 0.9), rgba(10, 24, 45, 0.88));
}

.summary-grid span { color: var(--muted); }
.summary-grid strong { font-size: clamp(20px, 2.6vw, 32px); }

.portal-tabs {
    display: flex;
    gap: 8px;
    margin: 0 0 18px;
    padding: 5px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: rgba(9, 21, 40, 0.78);
    width: fit-content;
}

.portal-tab {
    min-height: 40px;
    border: 0;
    border-radius: 10px;
    padding: 0 18px;
    color: var(--muted);
    background: transparent;
    cursor: pointer;
    font-weight: 800;
}

.portal-tab.is-active {
    color: #03131d;
    background: linear-gradient(135deg, var(--cyan), var(--teal));
}

[data-portal-panel][hidden],
.portal-tab[hidden],
.portal-dialog-overlay[hidden] {
    display: none !important;
}

.matrix-card {
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 22px;
    background: rgba(9, 21, 40, 0.94);
    box-shadow: var(--shadow);
}

.matrix-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 24px;
    padding: 22px;
    border-bottom: 1px solid var(--border);
}

.matrix-heading p { margin-bottom: 0; }
.matrix-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.date-control { min-width: 150px; }
.date-control input { min-height: 44px; color-scheme: dark; }

.matrix-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-height: 54px;
    padding: 10px 22px;
    border-bottom: 1px solid var(--border);
}

.matrix-meta p { margin: 0; color: var(--muted); }
.legend { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 7px; }
.legend-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 9px;
    border: 1px solid color-mix(in srgb, var(--alert-color) 65%, transparent);
    border-radius: 999px;
    color: var(--text);
    font-size: 12px;
    background: color-mix(in srgb, var(--alert-color) 12%, transparent);
}
.legend-chip i { width: 7px; height: 7px; border-radius: 50%; background: var(--alert-color); }

.matrix-scroll {
    max-width: 100%;
    overflow: auto;
    overscroll-behavior-inline: contain;
}

.hourly-matrix {
    width: max-content;
    min-width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    table-layout: fixed;
}

.hourly-matrix th, .hourly-matrix td {
    height: 44px;
    padding: 8px 12px;
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    text-align: right;
    white-space: nowrap;
}

.hourly-matrix thead th {
    position: sticky;
    top: 0;
    z-index: 5;
    color: #dffcff;
    background: #0b776f;
    text-align: center;
}

.sticky-cell { position: sticky; z-index: 7; background: var(--surface-sticky); }
.name-column { left: 0; width: 240px; min-width: 240px; text-align: left !important; }
.id-column { left: 240px; width: 190px; min-width: 190px; text-align: left !important; }
.metric-column { left: 430px; width: 82px; min-width: 82px; text-align: left !important; }
thead .sticky-cell { z-index: 9; background: #106d69; }
.hour-column { width: 102px; min-width: 102px; }
.hour-column.has-batch { background: #148b83; }
.play-row:hover > :not(.sticky-cell), .growth-row:hover > :not(.sticky-cell) { background: rgba(45, 212, 191, 0.08); }
.play-row:hover > .sticky-cell { background: #17304a; }
.growth-row:hover > .sticky-cell { background: #10243a; }
.growth-row .sticky-cell { background: #0d1b31; }
.matrix-value { color: #dbeafe; background: rgba(15, 23, 42, 0.44); }
.matrix-empty { color: #64748b; text-align: center !important; }
.matrix-error { color: #fecdd3; background: rgba(190, 24, 93, 0.2); text-align: center !important; }
.matrix-growth { color: #99f6e4; font-size: 13px; font-weight: 700; }
.matrix-alert {
    color: #fff;
    box-shadow: inset 0 0 0 2px var(--alert-color);
    background: color-mix(in srgb, var(--alert-color) 20%, #0f172a);
}
.disabled-badge { display: block; margin-top: 2px; color: #fda4af; font-size: 11px; }
.empty-state { min-width: 100%; height: 180px !important; color: var(--muted); text-align: center !important; }

.target-card {
    padding: clamp(20px, 3vw, 30px);
    border: 1px solid var(--border);
    border-radius: 22px;
    background: rgba(9, 21, 40, 0.94);
    box-shadow: var(--shadow);
}

.target-heading {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 22px;
}

.target-heading p {
    max-width: 850px;
    margin-bottom: 0;
    color: var(--muted);
}

.target-form,
.target-file-form {
    display: grid;
    gap: 10px;
    max-width: 820px;
}

.target-form label,
.target-file-form label {
    font-weight: 800;
}

.target-form textarea,
.target-file-form input {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 14px;
    color: var(--text);
    background: rgba(4, 12, 25, 0.72);
}

.target-form textarea {
    min-height: 126px;
    resize: vertical;
    font: 650 14px/1.55 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.target-form small,
.target-file-form small {
    color: var(--muted);
}

.target-form .button,
.target-file-form .button {
    width: fit-content;
}

.target-import-details {
    max-width: 820px;
    margin: 18px 0 10px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.target-import-details summary {
    width: fit-content;
    margin-bottom: 14px;
    color: #a5b4fc;
    cursor: pointer;
    font-weight: 800;
}

.target-table-scroll {
    max-width: 100%;
    margin-top: 22px;
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: 16px;
}

.target-table {
    width: 100%;
    min-width: 760px;
    border-collapse: collapse;
}

.target-table th,
.target-table td {
    padding: 13px 15px;
    border-bottom: 1px solid var(--border);
    text-align: left;
}

.target-table th {
    color: var(--muted);
    background: rgba(18, 35, 61, 0.78);
    font-size: 12px;
    letter-spacing: 0.04em;
}

.target-table tr:last-child td { border-bottom: 0; }
.target-table code { color: #bfdbfe; }
.target-table td small {
    display: inline-block;
    max-width: 360px;
    margin-top: 5px;
    color: var(--muted);
    line-height: 1.45;
}
.target-actions {
    display: flex;
    min-width: 190px;
    flex-wrap: wrap;
    gap: 8px;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    padding: 3px 9px;
    border-radius: 999px;
    color: #a7f3d0;
    background: rgba(5, 150, 105, 0.18);
    font-size: 12px;
    font-weight: 800;
}

.status-badge.is-disabled {
    color: #cbd5e1;
    background: rgba(100, 116, 139, 0.2);
}

.portal-dialog-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(2, 6, 23, 0.82);
    backdrop-filter: blur(8px);
}

.portal-dialog-card {
    width: min(540px, 100%);
    padding: 26px;
    border: 1px solid rgba(103, 232, 249, 0.34);
    border-radius: 20px;
    background: #0f1d34;
    box-shadow: var(--shadow);
}

.portal-dialog-details {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin: 20px 0;
}

.portal-dialog-details div {
    min-width: 0;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: rgba(4, 12, 25, 0.5);
}

.portal-dialog-details dt { color: var(--muted); font-size: 12px; }
.portal-dialog-details dd { margin: 3px 0 0; overflow-wrap: anywhere; font-weight: 800; }
.portal-dialog-warning { padding: 12px 14px; border-left: 4px solid #f59e0b; border-radius: 8px; color: #fde68a; background: rgba(120, 53, 15, 0.24); }
.portal-dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
body.portal-dialog-open { overflow: hidden; }

footer { padding: 18px 4px 0; text-align: center; font-size: 13px; }

@media (max-width: 900px) {
    .portal-header, .matrix-heading, .matrix-meta { flex-direction: column; align-items: stretch; }
    .account-panel { justify-content: space-between; }
    .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .matrix-actions, .legend { justify-content: flex-start; }
}

@media (max-width: 560px) {
    .dashboard-shell { padding: 16px 10px 24px; }
    .summary-grid { gap: 8px; }
    .summary-grid article { min-height: 88px; padding: 13px; }
    .matrix-card { border-radius: 16px; }
    .matrix-heading, .matrix-meta { padding: 16px; }
    .matrix-actions .button, .date-control { flex: 1 1 calc(50% - 4px); }
    .name-column { width: 176px; min-width: 176px; }
    .id-column { left: 176px; width: 154px; min-width: 154px; }
    .metric-column { left: 330px; width: 72px; min-width: 72px; }
    .portal-tabs { width: 100%; }
    .portal-tab { flex: 1; }
    .target-card { border-radius: 16px; }
    .portal-dialog-overlay { padding: 10px; }
    .portal-dialog-card { padding: 20px; }
    .portal-dialog-details { grid-template-columns: 1fr; }
}

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