:root {
    --bg: #f5f6fa;
    --white: #ffffff;
    --dark: #1a1a2e;
    --blue: #2B579A;
    --blue-light: #e8f0fe;
    --green: #27ae60;
    --green-light: #e8f5e9;
    --orange: #e67e22;
    --orange-light: #fff3e0;
    --gray-100: #f8f9fc;
    --gray-200: #eee;
    --gray-300: #ddd;
    --gray-400: #bbb;
    --gray-500: #888;
    --gray-600: #555;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'DM Sans', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: #333;
    line-height: 1.5;
}

/* ─── Topbar ─── */
.topbar {
    background: var(--dark);
    color: #fff;
    padding: 0 24px;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
}
.topbar-left { display: flex; align-items: center; gap: 14px; }
.topbar-right { display: flex; align-items: center; gap: 16px; }
.topbar-brand { font-weight: 700; font-size: 18px; color: #fff; text-decoration: none; }
.topbar-badge {
    font-size: 11px; color: #8899bb; background: rgba(255,255,255,0.1);
    padding: 3px 10px; border-radius: 10px;
}
.topbar-link {
    color: #8899bb; text-decoration: none; font-size: 13px; font-weight: 500;
    padding: 4px 10px; border-radius: 6px; transition: all 0.15s;
}
.topbar-link:hover, .topbar-link.active { color: #fff; background: rgba(255,255,255,0.1); }
.topbar-user { font-size: 13px; color: #aab; }
.topbar-logout {
    background: rgba(255,255,255,0.1); border: none; color: #fff;
    padding: 5px 14px; border-radius: 6px; font-size: 12px;
    text-decoration: none; transition: background 0.15s;
}
.topbar-logout:hover { background: rgba(255,255,255,0.2); }

/* ─── Container ─── */
.container { max-width: 1100px; margin: 0 auto; padding: 24px; }

/* ─── Cards ─── */
.card {
    background: var(--white); border-radius: var(--radius);
    padding: 20px; box-shadow: var(--shadow); margin-bottom: 16px;
}
.card-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 16px;
}
.card-title { font-size: 16px; font-weight: 700; }

/* ─── Stats row ─── */
.stats-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 24px; }
.stat-card {
    background: var(--white); border-radius: var(--radius); padding: 16px 20px;
    box-shadow: var(--shadow); border-left: 4px solid var(--gray-400);
}
.stat-card.blue { border-left-color: var(--blue); }
.stat-card.green { border-left-color: var(--green); }
.stat-card.orange { border-left-color: var(--orange); }
.stat-value { font-size: 24px; font-weight: 700; }
.stat-card.blue .stat-value { color: var(--blue); }
.stat-card.green .stat-value { color: var(--green); }
.stat-card.orange .stat-value { color: var(--orange); }
.stat-label { font-size: 12px; color: var(--gray-500); margin-top: 2px; }

/* ─── Task list ─── */
.task-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 16px; background: var(--gray-100); border-radius: 8px;
    margin-bottom: 8px;
}
.task-item.completed { background: var(--green-light); }
.task-term { font-weight: 600; font-size: 14px; }
.task-meta { font-size: 12px; color: var(--gray-500); margin-top: 2px; }
.task-progress { text-align: right; }
.task-progress-text { font-size: 13px; font-weight: 600; }
.progress-bar {
    width: 80px; height: 6px; background: #e0e0e0; border-radius: 3px;
    margin-top: 4px; overflow: hidden;
}
.progress-bar-fill { height: 100%; background: var(--blue); border-radius: 3px; }

/* ─── Buttons ─── */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 16px; border: none; border-radius: 8px;
    font-size: 13px; font-weight: 600; cursor: pointer;
    text-decoration: none; transition: all 0.15s;
    font-family: inherit;
}
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: #1e4080; }
.btn-success { background: var(--green); color: #fff; }
.btn-success:hover { background: #1e8e4e; }
.btn-secondary { background: var(--gray-100); color: var(--gray-600); }
.btn-secondary:hover { background: var(--gray-200); }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn:disabled { opacity: 0.4; cursor: default; }

/* ─── Dimension badges ─── */
.dim-badge {
    display: inline-block; padding: 2px 8px; border-radius: 4px;
    font-size: 11px; font-weight: 600; color: #fff;
}
.dim-productive { background: #4472C4; }
.dim-reproductive { background: #70AD47; }
.dim-power { background: #BF8F00; }

/* ─── Forms ─── */
.form-group { margin-bottom: 14px; }
.form-label { display: block; font-size: 12px; font-weight: 600; color: var(--gray-600); margin-bottom: 4px; }
.form-hint { font-weight: 400; color: var(--gray-500); margin-left: 6px; }
.form-control {
    width: 100%; padding: 8px 10px; border: 1px solid var(--gray-300);
    border-radius: 6px; font-size: 13px; font-family: inherit;
}
.form-control:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 2px rgba(43,87,154,0.15); }
select.form-control { appearance: auto; }
textarea.form-control { resize: vertical; }
.form-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }

/* ─── Gender selector ─── */
.gender-selector { display: flex; gap: 0; margin: 6px 0; }
.gender-btn {
    flex: 1; padding: 10px 4px; border: none; cursor: pointer;
    font-size: 11px; font-weight: 500; transition: all 0.15s;
    font-family: inherit; color: #777; background: #f5f5f5;
}
.gender-btn:first-child { border-radius: 6px 0 0 6px; }
.gender-btn:last-child { border-radius: 0 6px 6px 0; }
.gender-btn:not(:last-child) { border-right: 1px solid #e0e0e0; }
.gender-btn.active { color: #fff; font-weight: 700; background: var(--blue); }
.gender-label { text-align: center; font-size: 11px; color: var(--gray-600); margin-top: 4px; }
.gender-na-btn {
    display: block; margin: 6px auto 0; font-size: 10px; color: var(--gray-500);
    background: none; border: 1px solid var(--gray-300); border-radius: 4px;
    padding: 2px 8px; cursor: pointer; font-family: inherit;
}
.gender-na-btn.active { color: var(--blue); background: var(--blue-light); border-color: var(--blue); font-weight: 600; }

/* ─── MST selector ─── */
.mst-selector { display: flex; gap: 3px; align-items: center; margin: 6px 0; }
.mst-btn {
    width: 30px; height: 30px; border-radius: 6px; border: 2px solid #ccc;
    cursor: pointer; transition: all 0.15s;
}
.mst-btn.active { border: 3px solid var(--blue); transform: scale(1.15); box-shadow: 0 2px 8px rgba(43,87,154,0.3); }
.mst-na-btn {
    font-size: 10px; color: var(--gray-500); background: #f5f5f5;
    border: 1px solid var(--gray-300); border-radius: 4px;
    padding: 4px 6px; cursor: pointer; margin-left: 4px; font-family: inherit;
}
.mst-label { font-size: 11px; color: var(--gray-600); margin-top: 4px; }
.mst-ref-toggle {
    font-size: 11px; color: var(--blue); background: none; border: none;
    cursor: pointer; text-decoration: underline; margin-left: 6px; font-family: inherit;
}
.mst-reference {
    margin-top: 8px; padding: 12px; background: #fafafa; border: 1px solid #e0e0e0;
    border-radius: 8px; display: none;
}
.mst-reference.show { display: block; }
.mst-ref-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.mst-ref-swatch { width: 100%; height: 32px; border-radius: 6px; border: 1px solid #ddd; }
.mst-ref-label { font-size: 10px; font-weight: 600; text-align: center; }

/* ─── People selector ─── */
.people-selector { display: flex; gap: 6px; margin-top: 4px; }
.people-btn {
    padding: 6px 14px; border-radius: 6px; font-size: 12px; cursor: pointer;
    border: 1px solid var(--gray-300); background: var(--white); color: var(--gray-600);
    font-family: inherit; font-weight: 400; transition: all 0.15s;
}
.people-btn.active {
    border: 2px solid var(--blue); background: var(--blue-light);
    color: var(--blue); font-weight: 700;
}

/* ─── Two column layout ─── */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

/* ─── Image preview ─── */
.image-preview {
    background: #f0f0f0; border-radius: 8px; min-height: 240px;
    display: flex; align-items: center; justify-content: center;
    overflow: hidden; position: relative;
}
.image-preview img { max-width: 100%; max-height: 400px; object-fit: contain; }
.image-meta {
    display: flex; gap: 12px; flex-wrap: wrap; font-size: 11px; color: #777;
    padding: 8px 12px; background: var(--gray-100); border-radius: 6px; margin-top: 8px;
}

/* ─── Table ─── */
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
    padding: 10px 12px; text-align: left; font-weight: 600;
    color: var(--gray-600); background: var(--gray-100);
    border-bottom: 2px solid var(--gray-200);
}
.table td { padding: 10px 12px; border-bottom: 1px solid #f0f0f0; }

/* ─── Balance charts ─── */
.chart-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.chart-card {
    border: 1px solid var(--gray-200); border-radius: var(--radius); padding: 16px;
}
.chart-title { font-weight: 600; font-size: 14px; margin-bottom: 10px; }
.chart-bar-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.chart-bar-label { font-size: 11px; width: 100px; color: var(--gray-600); flex-shrink: 0; }
.chart-bar-track { flex: 1; height: 8px; background: #f0f0f0; border-radius: 4px; overflow: hidden; }
.chart-bar-fill { height: 100%; border-radius: 4px; transition: width 0.3s; }
.chart-bar-value { font-size: 11px; font-weight: 600; width: 60px; text-align: right; flex-shrink: 0; }
.chart-warning { margin-top: 8px; font-size: 11px; color: var(--orange); font-weight: 500; }
.mst-bars { display: flex; gap: 3px; align-items: flex-end; height: 80px; }
.mst-bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; }
.mst-bar { width: 100%; border-radius: 3px 3px 0 0; transition: height 0.3s; }
.mst-bar-count { font-size: 9px; color: var(--gray-500); margin-bottom: 1px; }
.mst-bar-num { font-size: 9px; color: var(--gray-500); margin-top: 2px; }

/* ─── Term filter buttons ─── */
.term-filter { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.term-filter-btn {
    padding: 6px 14px; border-radius: 6px; font-size: 12px; cursor: pointer;
    border: 1px solid var(--gray-300); background: var(--white);
    color: var(--gray-600); font-family: inherit; transition: all 0.15s;
}
.term-filter-btn.active {
    border: 2px solid var(--blue); background: var(--blue-light);
    color: var(--blue); font-weight: 700;
}

/* ─── Flash messages ─── */
.flash {
    padding: 10px 16px; border-radius: 8px; margin-bottom: 16px;
    font-size: 13px; font-weight: 500;
}
.flash-error { background: #fde8e8; color: #c0392b; }
.flash-success { background: var(--green-light); color: var(--green); }

/* ─── Login ─── */
.login-wrapper {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
}
.login-card {
    background: var(--white); border-radius: 16px; padding: 48px 40px;
    width: 380px; box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.login-title { font-size: 28px; font-weight: 700; color: var(--dark); text-align: center; }
.login-subtitle { font-size: 13px; color: var(--gray-500); text-align: center; letter-spacing: 1px; margin-top: 4px; margin-bottom: 32px; }
.login-input {
    width: 100%; padding: 10px 12px; border: 1px solid var(--gray-300);
    border-radius: 8px; font-size: 14px; font-family: inherit; margin-top: 4px;
}
.login-input:focus { outline: none; border-color: var(--blue); }
.login-label { font-size: 13px; color: var(--gray-600); font-weight: 500; display: block; margin-bottom: 16px; }

/* ─── Annotation table (compact) ─── */
.ann-table { width: 100%; border-collapse: collapse; font-size: 11px; }
.ann-table th {
    padding: 6px 8px; text-align: left; font-weight: 600;
    color: var(--gray-600); background: var(--gray-100);
    border-bottom: 1px solid var(--gray-200);
}
.ann-table td { padding: 6px 8px; border-bottom: 1px solid #f5f5f5; }
.gender-dot {
    display: inline-block; width: 10px; height: 10px; border-radius: 50%;
    vertical-align: middle; margin-right: 4px; border: 1px solid #ddd;
}
.mst-dot {
    display: inline-block; width: 14px; height: 14px; border-radius: 3px;
    vertical-align: middle; margin-right: 3px; border: 1px solid #ccc;
}

/* ─── User management ─── */
.user-form { display: grid; grid-template-columns: 1fr 1fr 1fr auto auto; gap: 10px; align-items: end; }
.user-form .form-group { margin-bottom: 0; }

/* ─── Responsive ─── */
@media (max-width: 768px) {
    .two-col { grid-template-columns: 1fr; }
    .stats-row { grid-template-columns: repeat(2, 1fr); }
    .chart-grid { grid-template-columns: 1fr; }
    .form-row { grid-template-columns: 1fr; }
    .user-form { grid-template-columns: 1fr; }
}
