:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --success: #10b981;
    --danger: #ef4444;
    --bg-color: #f1f5f9;
    --card-bg: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --radius: 12px;
}

body {
    margin: 0;
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    display: flex;
    justify-content: center;
    padding: 30px 20px;
    min-height: 100vh;
    overscroll-behavior-y: none;
}

.main-wrapper { width: 100%; max-width: 1100px; }

header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 25px; flex-wrap: wrap; gap: 15px; }
header h1 { margin: 0; font-size: 1.6rem; color: var(--text-main); font-weight: 700; letter-spacing: -0.5px; }

.nav-tabs { background: #e2e8f0; padding: 4px; border-radius: 10px; display: flex; gap: 5px; }
.nav-btn { background: transparent; border: none; padding: 8px 16px; border-radius: 8px; cursor: pointer; font-weight: 600; color: var(--text-muted); transition: all 0.2s; margin: 0; width: auto; font-size: 0.9rem; display: flex; align-items: center; gap: 6px; }
.nav-btn:hover { color: var(--text-main); }
.nav-btn.active { background: white; color: var(--primary); box-shadow: var(--shadow-sm); }

.content-grid { display: flex; gap: 24px; flex-wrap: wrap; animation: fadeIn 0.4s ease-out; }
.card { background: var(--card-bg); border-radius: var(--radius); padding: 24px; flex: 1; min-width: 320px; box-shadow: var(--shadow-md); border: 1px solid var(--border); display: flex; flex-direction: column; }
.full-width { flex-basis: 100%; }
.card-header h2 { margin: 0 0 20px 0; font-size: 1.1rem; color: var(--text-main); border-bottom: 2px solid var(--bg-color); padding-bottom: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }

.input-group { margin-bottom: 16px; position: relative; }
.row { display: flex; gap: 12px; }
.half { flex: 1; }
.date-time-row { display: flex; gap: 8px; }

label { display: block; margin-bottom: 6px; font-weight: 500; font-size: 0.85rem; color: var(--text-muted); }
input, select { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 16px; box-sizing: border-box; transition: border-color 0.2s, box-shadow 0.2s; background: #f8fafc; appearance: none; }
input:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1); background: white; }
input:disabled { background: #e2e8f0; color: #94a3b8; cursor: not-allowed; }

.toggle-wrapper { display: flex; align-items: center; gap: 12px; margin-top: 20px; background: #f1f5f9; padding: 10px 15px; border-radius: 8px; }
.switch { position: relative; display: inline-block; width: 44px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #cbd5e1; transition: .3s; border-radius: 24px; }
.slider:before { position: absolute; content: ""; height: 18px; width: 18px; left: 3px; bottom: 3px; background-color: white; transition: .3s; border-radius: 50%; box-shadow: 0 2px 4px rgba(0,0,0,0.2); }
input:checked + .slider { background-color: var(--primary); }
input:checked + .slider:before { transform: translateX(20px); }

.tooltip-container { position: relative; cursor: help; border-bottom: 1px dotted #999; display: inline-block; }
.tooltip-text { visibility: hidden; width: 220px; background-color: #1e293b; color: #fff; text-align: center; border-radius: 6px; padding: 8px 10px; position: absolute; z-index: 10; bottom: 135%; left: 50%; margin-left: -110px; opacity: 0; transition: opacity 0.3s; font-size: 0.8rem; font-weight: normal; box-shadow: 0 4px 6px rgba(0,0,0,0.2); pointer-events: none; }
.tooltip-text::after { content: ""; position: absolute; top: 100%; left: 50%; margin-left: -5px; border-width: 5px; border-style: solid; border-color: #1e293b transparent transparent transparent; }
.tooltip-container:hover .tooltip-text { visibility: visible; opacity: 1; }
.badge-plus { background: #fee2e2; color: #b91c1c; font-size: 0.75rem; padding: 3px 8px; border-radius: 99px; font-weight: 700; margin-left: auto; }

button { width: 100%; padding: 12px; border: none; border-radius: 8px; cursor: pointer; font-weight: 600; font-size: 0.95rem; margin-top: 5px; transition: transform 0.1s, background 0.2s; }
button:active { transform: scale(0.98); }
.btn-primary { background: var(--primary); color: white; box-shadow: 0 4px 6px -1px rgba(37, 99, 235, 0.3); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: var(--success); color: white; box-shadow: 0 4px 6px -1px rgba(16, 185, 129, 0.3); }
.btn-outline { background: white; border: 2px solid var(--primary); color: var(--primary); margin-top: 15px; }
.btn-outline:hover { background: #eff6ff; }
.btn-reset { width: auto; padding: 8px 15px; background: #94a3b8; color: white; font-size: 0.85rem; margin-top: 0; }
.btn-reset:hover { background: #64748b; }
.btn-danger { background: var(--danger); color: white; margin-top: 10px; box-shadow: 0 4px 6px -1px rgba(239, 68, 68, 0.3); }
.btn-danger:hover { background: #dc2626; }
.btn-group-col { display: flex; flex-direction: column; gap: 5px; margin-top: 10px; }

.result-box { background: #eff6ff; padding: 15px; border-radius: 8px; margin-top: 20px; border: 1px solid #bfdbfe; }
.result-row { display: flex; justify-content: space-between; margin-bottom: 8px; font-size: 1.05rem; }

.disabled-look { opacity: 0.6; pointer-events: none; filter: grayscale(0.8); transition: 0.3s; }
.disabled-look.active { opacity: 1; pointer-events: all; filter: none; background: #f0fdf4; padding: 20px; border-radius: 12px; border: 1px solid #86efac; margin-bottom: 20px; box-shadow: 0 4px 12px rgba(16, 185, 129, 0.1); }
.weekday-hint { margin: -10px 0 15px 0; font-size: 0.9rem; color: var(--primary); font-weight: 600; }

.history-section { flex-grow: 1; display: flex; flex-direction: column; min-height: 0; }
.history-tree { overflow-y: auto; max-height: 400px; padding-right: 5px; }
.history-tree details { margin-bottom: 8px; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.history-tree summary { padding: 10px; background: #f8fafc; cursor: pointer; font-weight: 600; font-size: 0.9rem; transition: background 0.2s; list-style: none; }
.history-tree summary:hover { background: #e2e8f0; }
.tree-entry { display: flex; justify-content: space-between; padding: 10px 15px; border-top: 1px solid var(--border); cursor: pointer; background: white; transition: background 0.2s; }
.tree-entry:hover { background: #f1f5f9; }
.tree-entry.active { background: #eff6ff; border-left: 4px solid var(--primary); padding-left: 11px; }

.detail-view { background: #fff; margin-top: 20px; animation: fadeIn 0.3s; }
.comparison-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.comp-card { background: #f8fafc; padding: 12px; border-radius: 8px; text-align: center; border: 1px solid var(--border); }
.comp-card small { display: block; color: var(--text-muted); font-size: 0.7rem; text-transform: uppercase; margin-bottom: 4px; font-weight: 700; }
.comp-val { font-weight: 700; font-size: 1rem; color: var(--text-main); }
.diff-positive { background: #ecfdf5; border-color: #6ee7b7; color: #047857; }
.diff-negative { background: #fef2f2; border-color: #fca5a5; color: #b91c1c; }
.highlight { color: var(--primary); }

.stats-controls { display: flex; flex-wrap: wrap; gap: 20px; border-bottom: 1px solid var(--border); padding-bottom: 20px; margin-bottom: 20px; align-items: flex-start; }
.filter-group { display: flex; gap: 15px; flex-wrap: wrap; width: 100%; }
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 20px; margin-bottom: 30px; }
.kpi-card { background: #f8fafc; padding: 20px; border-radius: 12px; text-align: center; border: 1px solid var(--border); box-shadow: var(--shadow-sm); }
.kpi-card strong { font-size: 1.5rem; color: var(--primary); display: block; margin-top: 5px; }
.chart-container { position: relative; height: 350px; width: 100%; }

.hidden { display: none !important; }
.status-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; margin-right: 8px; }
.s-est { background: #f59e0b; } .s-com { background: var(--success); }
.toast { position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%); background: #1e293b; color: white; padding: 12px 24px; border-radius: 99px; z-index: 999; box-shadow: 0 10px 15px -3px rgba(0,0,0,0.3); font-weight: 500; animation: slideUp 0.3s; }

.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); z-index: 2000; display: flex; justify-content: center; align-items: center; }
.modal-content { background: white; padding: 25px; border-radius: 16px; max-width: 400px; width: 90%; text-align: center; box-shadow: 0 10px 25px rgba(0,0,0,0.2); }
.modal-content h3 { margin-top: 0; color: var(--text-main); }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; justify-content: center; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideUp { from { transform: translate(-50%, 20px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }

@media (max-width: 768px) {
    body { padding: 10px; display: block; }
    .content-grid { flex-direction: column; }
    .card { width: 100%; box-sizing: border-box; margin-bottom: 15px; }
    .comparison-grid { grid-template-columns: 1fr; }
    .nav-tabs { width: 100%; justify-content: center; }
    .filter-group { flex-direction: column; }
    .filter-group select, .filter-group button { width: 100%; }
}