/* ===== Monochrome Slate — Light Sidebar ===== */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    --gray-50:  #fafafa;
    --gray-100: #f4f4f5;
    --gray-200: #e4e4e7;
    --gray-300: #d4d4d8;
    --gray-400: #a1a1aa;
    --gray-500: #71717a;
    --gray-600: #52525b;
    --gray-700: #3f3f46;
    --gray-800: #27272a;
    --gray-900: #18181b;
    --gray-950: #09090b;

    --bg:       var(--gray-100);
    --card:     #ffffff;
    --text:     var(--gray-900);
    --text-secondary: var(--gray-600);
    --text-muted: var(--gray-500);
    --text-faint: var(--gray-400);
    --border:   var(--gray-200);

    --danger:    #ef4444;
    --danger-bg: #fef2f2;
    --success:   #22c55e;
    --success-bg:#f0fdf4;

    --font: 'Inter', system-ui, -apple-system, sans-serif;
    --radius: 8px;
    --radius-sm: 6px;
}

/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; }

body {
    font-family: var(--font);
    background: var(--bg);
    margin: 0;
    color: var(--text);
    line-height: 1.6;
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}

h2 {
    color: var(--text);
    margin: 0 0 20px;
    font-weight: 600;
    font-size: 1.25rem;
    letter-spacing: -0.02em;
}

a {
    color: var(--text);
    text-decoration: underline;
    text-decoration-color: var(--gray-300);
    text-underline-offset: 2px;
    transition: text-decoration-color 0.1s;
}
a:hover { text-decoration-color: var(--text); }

/* ===== Layout ===== */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* ===== Sidebar (light) ===== */
.sidebar {
    width: 232px;
    min-width: 232px;
    background: var(--card);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    overflow-y: auto;
}

.sidebar-logo {
    padding: 24px 20px 20px;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.02em;
}

.sidebar nav {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 0 8px;
    gap: 2px;
}

.sidebar nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    color: var(--text-muted);
    font-size: 0.8125rem;
    font-weight: 500;
    border-radius: var(--radius-sm);
    text-decoration: none;
    transition: color 0.1s, background 0.1s;
}

.sidebar nav a:hover {
    background: var(--gray-100);
    color: var(--text);
}

.sidebar nav a.active {
    background: var(--gray-100);
    color: var(--text);
    font-weight: 600;
}

.sidebar nav a .nav-icon {
    font-size: 0.9375rem;
    width: 18px;
    text-align: center;
    flex-shrink: 0;
    opacity: 0.5;
}

.sidebar nav a:hover .nav-icon,
.sidebar nav a.active .nav-icon {
    opacity: 0.8;
}

.sidebar-logout {
    padding: 14px 20px;
    color: var(--text-faint) !important;
    font-size: 0.75rem;
    font-weight: 500;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none !important;
    transition: color 0.1s;
}

.sidebar-logout:hover {
    color: var(--text-muted) !important;
    background: var(--gray-50);
}

/* ===== Main Content ===== */
.main-content {
    flex: 1;
    margin-left: 232px;
    padding: 36px 40px;
    min-height: 100vh;
    max-width: 1200px;
}

.page-header { margin-bottom: 32px; padding-bottom: 16px; border-bottom: 1px solid var(--border); }
.page-header h2 { margin: 0; }

/* ===== Cards ===== */
.card {
    background: var(--card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 24px;
    margin-bottom: 24px;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.8125rem;
    font-weight: 500;
    font-family: var(--font);
    transition: background 0.1s, border-color 0.1s, color 0.1s;
    line-height: 1.5;
    background: var(--card);
    color: var(--text);
}

.btn:hover {
    background: var(--gray-50);
    border-color: var(--gray-300);
}

.btn-primary {
    background: #3b82f6;
    color: #fff;
    border-color: #3b82f6;
}
.btn-primary:hover {
    background: #2563eb;
    border-color: #2563eb;
}

.btn-danger {
    color: var(--danger);
    background: var(--card);
    border-color: var(--border);
}
.btn-danger:hover {
    background: var(--danger-bg);
    border-color: #fecaca;
}

.btn-success {
    color: var(--success);
    background: var(--card);
    border-color: var(--border);
}
.btn-success:hover {
    background: var(--success-bg);
    border-color: #bbf7d0;
}

.btn-info,
.btn-secondary {
    color: var(--text-muted);
    background: var(--card);
    border-color: var(--border);
}
.btn-info:hover,
.btn-secondary:hover {
    background: var(--gray-50);
    color: var(--text);
}

.btn-sm { padding: 4px 8px; font-size: 0.75rem; }

/* Icon buttons */
.btn-icon {
    padding: 5px 7px;
    font-size: 1rem;
    line-height: 1;
    min-width: 30px;
}

.btn-icon:hover { background: var(--gray-50); }
.btn-icon.btn-danger:hover { background: var(--danger-bg); }

/* ===== Tables ===== */
table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 16px;
}

th, td {
    padding: 5px 14px;
    text-align: left;
    height: 39px;
    vertical-align: middle;
}
td {
    border-bottom: 1px solid transparent;
}

th {
    border-bottom: 1px solid var(--border);
    font-weight: 700;
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    background: #f7f7f8;
    padding-bottom: 10px;
    padding-top: 14px;
}

tbody tr { transition: background 0.08s; }
tbody tr:hover { background: var(--gray-50); }

.actions { white-space: nowrap; text-align: right; padding-left: 4px; }
.actions button { margin-left: 4px; }

td.editable { cursor: pointer; }
td.editable input,
td.editable select {
    width: 100%;
    padding: 2px 14px;
    height: 28px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.8125rem;
    background: var(--card);
    color: var(--text);
    box-sizing: border-box;
}

td.editable input:focus,
td.editable select:focus {
    outline: none;
    border-color: var(--gray-400);
    box-shadow: 0 0 0 2px rgba(0,0,0,0.05);
}

.new-row { background-color: var(--gray-50); }

/* Number input spinners — subtle */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
    opacity: 0.4;
    margin-left: 5px;
}

.data-cell { text-align: right; font-variant-numeric: tabular-nums; cursor: pointer; }
.data-cell input {
    width: 100%;
    min-width: 0;
    padding: 2px 14px;
    height: 28px;
    border: none;
    border-bottom: 1px solid var(--gray-300);
    border-radius: 0;
    background: transparent;
    font-family: var(--font);
    font-size: 0.8125rem;
    text-align: right;
    color: var(--text);
    box-sizing: border-box;
    outline: none;
    -moz-appearance: textfield;
}
.data-cell input::-webkit-outer-spin-button,
.data-cell input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
.data-cell input:focus {
    border-bottom-color: var(--gray-900);
}

/* ===== Forms ===== */
.form-group { margin-bottom: 18px; }

label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-secondary);
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="month"],
select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.875rem;
    color: var(--text);
    background: var(--card);
    transition: border-color 0.1s;
}

input[type="text"]:focus,
input[type="password"]:focus,
input[type="number"]:focus,
input[type="month"]:focus,
select:focus {
    outline: none;
    border-color: var(--gray-400);
    box-shadow: 0 0 0 2px rgba(0,0,0,0.05);
}

input::placeholder { color: var(--text-faint); }

.help-block {
    color: var(--danger);
    font-size: 0.75rem;
    margin-top: 4px;
}

/* ===== Alerts ===== */
.alert {
    padding: 10px 14px;
    margin-bottom: 16px;
    border-radius: var(--radius-sm);
    font-size: 0.8125rem;
    font-weight: 500;
}

.alert-success {
    background: var(--success-bg);
    color: #15803d;
    border: 1px solid #bbf7d0;
}

.alert-danger {
    background: var(--danger-bg);
    color: #b91c1c;
    border: 1px solid #fecaca;
}

/* ===== Controls ===== */
.controls {
    display: flex;
    align-items: flex-end;
    gap: 24px;
    flex-wrap: wrap;
    margin-bottom: 24px;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.control-group label {
    display: block;
    margin-bottom: 0;
    font-weight: 500;
    color: var(--text-faint);
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.controls select,
.controls input[type="month"] {
    width: auto;
    padding: 6px 10px;
    font-size: 0.8125rem;
    height: 34px;
    box-sizing: border-box;
}

.controls .controls-btn {
    height: 34px;
    box-sizing: border-box;
}

.controls label {
    display: inline;
    margin-bottom: 0;
    font-weight: 500;
    color: var(--text-muted);
    font-size: 0.8125rem;
}

.month-nav {
    display: flex;
    align-items: center;
    gap: 4px;
}

.month-nav .btn { padding: 8px 8px; font-size: 0.75rem; height: 34px; width: 34px; box-sizing: border-box; }

.month-label {
    font-size: 0.8125rem;
    color: var(--text-muted);
    font-weight: 500;
    min-width: 120px;
}

/* ===== Toolbar Row (button + inline message) ===== */
.toolbar-row {
    display: flex;
    align-items: center;
    height: 34px;
}

.toolbar-row .btn { flex-shrink: 0; }

/* Message area — anchored to top-right of the card */
.card { position: relative; }

.card > #message-area {
    position: absolute;
    top: 16px;
    right: 24px;
    z-index: 5;
}

.card > #message-area .alert,
.toolbar-row .alert {
    margin-bottom: 0;
    padding: 6px 12px;
    white-space: nowrap;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.save-all-row { margin-top: 24px; text-align: right; }
.save-all-row .btn { padding: 8px 24px; font-size: 0.875rem; }

/* ===== TV Settings ===== */
.tv-settings {
    margin-top: 32px;
    padding-top: 24px;
    border-top: 1px solid var(--border);
}

.tv-settings select {
    width: auto;
    padding: 6px 10px;
    margin-right: 10px;
}

.tv-settings .tv-hint {
    margin-top: 12px;
    color: var(--text-faint);
    font-size: 0.75rem;
}

/* ===== Login ===== */
.login-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: var(--gray-100);
}

.login-card {
    width: 360px;
    max-width: 90vw;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 36px 32px;
}

.login-card h2 {
    text-align: center;
    margin-bottom: 28px;
    font-size: 1.375rem;
}

.login-card .btn {
    display: block;
    width: 100%;
    padding: 10px;
    font-size: 0.875rem;
}

.login-card .alert { text-align: center; }

/* ===== Dashboard Layout ===== */
.dashboard-layout {
    display: flex;
    min-height: 100vh;
}

.dashboard-main {
    flex: 1;
    margin-left: 232px;
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* ===== Control Bar ===== */
.control-bar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 10px 16px;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    flex-wrap: nowrap;
    min-height: 50px;
}

.control-group-inline {
    display: flex;
    align-items: center;
    gap: 8px;
}

.control-group-inline label {
    display: inline;
    margin-bottom: 0;
    font-weight: 500;
    color: var(--text-faint);
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
}

.control-bar select {
    width: auto;
    padding: 5px 10px;
    height: 34px;
    box-sizing: border-box;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.8125rem;
    font-family: var(--font);
}

.control-bar input[type="month"] {
    height: 34px;
    box-sizing: border-box;
    padding: 5px 10px;
    font-size: 0.8125rem;
}

.control-bar .controls-btn {
    height: 34px;
    box-sizing: border-box;
}

.control-bar .control-spacer {
    flex: 1;
}

/* ===== Dashboard Grid ===== */
.dashboard-container {
    padding: 8px;
    flex: 1;
}

@media (min-width: 481px) {
    .dashboard-container {
        display: grid;
        grid-template-rows: 1fr 1fr;
        grid-template-columns: 1fr 1fr;
        gap: 5px;
        height: calc(100vh - 48px);
        overflow: hidden;
    }
}

.grid-cell-container {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
    min-height: 0;
}

.top-left-area { grid-row: 1; grid-column: 1; }
.top-right-area { grid-row: 1; grid-column: 2; }
.total-doughnut-area { grid-row: 2; grid-column: 2; }

.doughnuts-grid-area {
    grid-row: 2;
    grid-column: 1;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-auto-rows: minmax(0, 1fr);
    gap: 0;
    row-gap: 0;
    min-height: 0;
    overflow: hidden;
}

.doughnut-chart-wrapper {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    padding: 0;
}

.doughnut-canvas-container {
    width: 100%;
    height: calc(100% - 36px);
    aspect-ratio: 1 / 1;
    max-width: 100%;
    max-height: 100%;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 1;
    min-height: 0;
    margin: 0;
}

.doughnut-title {
    text-align: center;
    font-weight: 600;
    color: var(--text);
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
    height: 18px;
    line-height: 18px;
    flex-shrink: 0;
    margin: 0;
    letter-spacing: -0.01em;
}

.doughnut-legend {
    display: flex;
    justify-content: space-around;
    width: 100%;
    height: 20px;
    flex-shrink: 0;
    margin: 0;
    overflow: hidden;
}

.doughnut-legend-item {
    display: flex;
    align-items: center;
    font-size: 10px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
}

.doughnut-legend-color {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 3px;
    flex-shrink: 0;
}

.doughnut-canvas-container canvas {
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    max-height: 100% !important;
}

/* ===== Responsive: dashboard ===== */
@media (min-width: 481px) and (max-width: 992px) {
    .doughnuts-grid-area { gap: 5px; column-gap: 2px; padding: 2px; }
    .doughnut-title { font-size: 11px; height: 18px; line-height: 16px; }
    .doughnut-legend-item { font-size: 10px; }
    .doughnut-legend-color { width: 6px; height: 6px; margin-right: 2px; }
    .doughnut-canvas-container { height: calc(100% - 32px); }
}

@media (max-width: 480px) {
    .dashboard-container {
        display: flex;
        flex-direction: column;
        min-height: calc(100vh - 48px);
        overflow-y: auto;
        gap: 12px;
        height: auto;
    }
    .grid-cell-container { width: 100%; height: auto; aspect-ratio: 1 / 1; margin-bottom: 12px; padding: 10px; }
    .total-doughnut-area { width: 100%; height: auto; padding: 10px; }
    .top-left-area { order: 2; }
    .top-right-area { order: 3; }
    .doughnuts-grid-area { order: 4; display: flex; flex-direction: column; gap: 12px; padding: 0; border: none; background: transparent; }
    .total-doughnut-area { order: 1; }
    .doughnuts-grid-area .doughnut-chart-wrapper {
        height: auto; width: 100%;
        background: var(--card);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        padding: 10px;
    }
    .doughnut-canvas-container { width: 100%; height: auto; aspect-ratio: 1 / 1; margin: 10px auto; min-height: 0; }
    .total-doughnut-area .doughnut-chart-wrapper { border: none; padding: 0; background: transparent; }
}

/* ===== TV ===== */
.tv-body {
    height: 100%;
    padding: 0;
    margin: 0;
    overflow: hidden;
    background: var(--bg);
    font-family: var(--font);
}

.tv-info {
    position: fixed;
    top: 8px;
    right: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-faint);
    font-weight: 500;
    z-index: 10;
}
.tv-info { text-decoration: none; transition: color 0.15s; }
.tv-info:hover { color: var(--text); }

.tv-body .dashboard-container { height: 100vh; padding: 8px; }
.tv-body .grid-cell-container,
.tv-body .doughnuts-grid-area { border-radius: var(--radius); }
.tv-body .doughnut-title { font-size: 15px; height: 20px; line-height: 20px; }
.tv-body .doughnut-legend { height: 22px; }
.tv-body .doughnut-legend-item { font-size: 13px; }
.tv-body .doughnut-legend-color { width: 10px; height: 10px; margin-right: 4px; }

.tv-not-configured {
    display: flex;
    min-height: 100vh;
    align-items: center;
    justify-content: center;
    background: var(--gray-900);
    color: var(--gray-50);
    font-family: var(--font);
}

/* ===== Confirm Modal ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.25);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: modalFadeIn 0.12s ease;
}

.modal-box {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    width: 360px;
    max-width: 90vw;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
}

.modal-box p {
    margin: 0 0 20px;
    font-size: 0.875rem;
    color: var(--text);
    line-height: 1.5;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.modal-actions .btn { min-width: 80px; }

.btn-danger-fill {
    background: var(--danger);
    color: #fff;
    border-color: var(--danger);
}
.btn-danger-fill:hover {
    background: #dc2626;
    border-color: #dc2626;
}

@keyframes modalFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ===== No data ===== */
.no-data-placeholder {
    display: flex;
    min-height: calc(100vh - 48px);
    align-items: center;
    justify-content: center;
    text-align: center;
}
.no-data-placeholder h2 { color: var(--text-muted); font-weight: 500; }
.no-data-placeholder p { color: var(--text-faint); }

/* ===== Mobile ===== */
.sidebar-toggle {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 200;
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    width: 36px;
    height: 36px;
    font-size: 1.1rem;
    cursor: pointer;
    align-items: center;
    justify-content: center;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.2);
    z-index: 90;
}

@media (max-width: 768px) {
    .sidebar-toggle { display: flex; }
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.15s ease;
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-overlay.open { display: block; }

    .main-content {
        margin-left: 0;
        padding: 24px 16px;
        padding-top: 56px;
    }
    .dashboard-main { margin-left: 0; }
    .dashboard-main .control-bar { padding-left: 52px; }
}
