* { box-sizing: border-box; }
:root {
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --primary-light: #eef2ff;
    --bg: #f6f7fb;
    --card: #ffffff;
    --border: #e5e7eb;
    --text: #1f2937;
    --text-muted: #6b7280;
    --danger: #dc2626;
    --danger-bg: #fee2e2;
    --success: #16a34a;
    --radius: 10px;
}
body {
    font-family: 'Inter', -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    margin: 0;
    font-size: 15px;
}

/* ---------- App shell (sidebar + main) ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 230px;
    background: #171a2b;
    color: #cbd0e6;
    display: flex;
    flex-direction: column;
    padding: 20px 0;
    flex-shrink: 0;
}
.sidebar .brand {
    font-weight: 700;
    font-size: 1.05rem;
    color: #fff;
    padding: 0 20px 20px;
    border-bottom: 1px solid #2a2e45;
    margin-bottom: 14px;
}
.sidebar .brand strong { color: #a5b4fc; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar nav a {
    color: #cbd0e6;
    text-decoration: none;
    padding: 11px 20px;
    font-size: 0.92rem;
    display: flex;
    align-items: center;
    gap: 10px;
    border-left: 3px solid transparent;
}
.sidebar nav a .ic { font-size: 1rem; }
.sidebar nav a:hover { background: #202339; color: #fff; }
.sidebar nav a.active { background: #202339; color: #fff; border-left-color: var(--primary); font-weight: 600; }
.sidebar-footer {
    padding: 14px 20px 0; border-top: 1px solid #2a2e45; margin-top: 10px;
    display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem;
}
.sidebar-footer a { color: #a5b4fc; text-decoration: none; }
.sidebar-footer a:hover { text-decoration: underline; }

.main-area { flex: 1; min-width: 0; }
main { max-width: 1180px; margin: 0 auto; padding: 28px 28px 60px; }

h1.page-title { font-size: 1.4rem; margin: 0 0 4px; }
.page-subtitle { color: var(--text-muted); margin: 0 0 24px; font-size: 0.92rem; }

/* ---------- Cards / fieldsets ---------- */
fieldset {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 22px;
    margin-bottom: 18px;
    box-shadow: 0 1px 2px rgba(16,24,40,0.03);
}
legend { font-weight: 600; color: var(--primary); padding: 0 8px; font-size: 0.95rem; }

.card {
    background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 20px 22px; margin-bottom: 20px; box-shadow: 0 1px 2px rgba(16,24,40,0.03);
}

label {
    display: inline-block;
    margin: 7px 14px 7px 0;
    font-size: 0.88rem;
    color: var(--text-muted);
    font-weight: 500;
}
input[type="text"], input[type="number"], input[type="date"], input[type="password"], select, textarea {
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.92rem;
    margin-top: 4px;
    font-family: inherit;
    color: var(--text);
    background: #fff;
    display: block;
}
input:focus, select:focus, textarea:focus {
    outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light);
}

.checklist { display: flex; flex-wrap: wrap; gap: 6px 20px; margin: 10px 0; }
.checklist label { margin: 3px 0; color: var(--text); font-weight: 400; display: flex; align-items: center; gap: 6px; }

.add-new-row { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; align-items: center; }
.add-new-row input, .add-new-row select { flex: 1; min-width: 160px; margin-top: 0; }
.add-new-row button, button.secondary-btn {
    background: var(--primary-light); color: var(--primary-dark); border: none; padding: 8px 14px;
    border-radius: 6px; cursor: pointer; font-size: 0.85rem; font-weight: 500;
}
.add-new-row button:hover, button.secondary-btn:hover { background: #e0e7ff; }

.repeat-row {
    display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
    background: #fafbfc; border: 1px solid var(--border); border-radius: 8px;
    padding: 10px; margin-bottom: 10px;
}
.remove-btn {
    background: var(--danger-bg); color: var(--danger); border: none; border-radius: 6px;
    width: 30px; height: 30px; cursor: pointer; font-size: 0.9rem;
}
.remove-btn:hover { background: #fecaca; }

.hint { color: var(--text-muted); font-size: 0.82rem; margin: 4px 0; }

.primary-btn {
    background: var(--primary); color: #fff; border: none;
    padding: 12px 30px; border-radius: 8px; font-size: 0.95rem; cursor: pointer; font-weight: 600;
}
.primary-btn:hover { background: var(--primary-dark); }

.btn-row { display: flex; gap: 10px; align-items: center; }
.link-btn { color: var(--primary); text-decoration: none; font-size: 0.88rem; font-weight: 500; }
.link-btn:hover { text-decoration: underline; }
.link-btn.danger { color: var(--danger); }

/* ---------- Stat cards ---------- */
.stat-cards { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.stat-card {
    background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px 26px;
    min-width: 150px; box-shadow: 0 1px 2px rgba(16,24,40,0.03);
}
.stat-card span { display: block; font-size: 1.9rem; font-weight: 700; color: var(--primary); }
.stat-card label { margin: 0; font-size: 0.82rem; }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 20px; }
.chart-card canvas { max-height: 280px; }
.chart-card h3 { margin: 0 0 12px; font-size: 0.98rem; }

/* ---------- Tables ---------- */
.data-table { width: 100%; border-collapse: collapse; background: var(--card); border-radius: var(--radius); overflow: hidden; margin-bottom: 24px; }
.data-table th, .data-table td { padding: 10px 14px; border-bottom: 1px solid #eef0f2; text-align: left; font-size: 0.88rem; }
.data-table th { background: #f9fafb; color: var(--text-muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; }
.data-table tr:hover td { background: #fafbff; }
.badge { display: inline-block; padding: 2px 10px; border-radius: 20px; font-size: 0.78rem; font-weight: 600; }
.badge.malignant { background: #fee2e2; color: #991b1b; }
.badge.benign { background: #dcfce7; color: #166534; }

/* ---------- Tabs (manage page) ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; flex-wrap: wrap; }
.tab-btn {
    background: none; border: none; padding: 10px 18px; cursor: pointer; font-size: 0.9rem;
    color: var(--text-muted); border-bottom: 2px solid transparent; font-weight: 500;
}
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.manage-row {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: 10px 14px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 8px; background: #fff;
}
.manage-row .name-edit { display: flex; align-items: center; gap: 8px; flex: 1; }
.manage-row input[type="text"] { margin: 0; }
.manage-row .actions { display: flex; gap: 6px; }
.manage-row .actions button { padding: 5px 10px; font-size: 0.78rem; }
.manage-row .usage-count { color: var(--text-muted); font-size: 0.78rem; margin-right: 6px; }
.tree-child { margin-left: 28px; }

.alert { padding: 10px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 0.88rem; }
.alert.success { background: #dcfce7; color: #166534; }
.alert.error { background: var(--danger-bg); color: var(--danger); }

/* ---------- Login page ---------- */
.login-page { display: flex; align-items: center; justify-content: center; height: 100vh; background: var(--bg); }
.login-box {
    background: #fff; padding: 36px 40px; border-radius: 14px;
    box-shadow: 0 4px 24px rgba(16,24,40,0.08); display: flex; flex-direction: column; gap: 14px; min-width: 320px;
}
.login-box h1 { margin: 0 0 6px; font-size: 1.4rem; color: var(--primary); }
.login-box .error { color: var(--danger); font-size: 0.88rem; background: var(--danger-bg); padding: 8px 12px; border-radius: 6px; }
.login-box button { margin-top: 6px; }

@media (max-width: 860px) {
    .app-shell { flex-direction: column; }
    .sidebar { width: 100%; flex-direction: row; overflow-x: auto; padding: 10px; }
    .sidebar .brand { display: none; }
    .sidebar nav { flex-direction: row; }
    .sidebar nav a { border-left: none; border-bottom: 3px solid transparent; white-space: nowrap; }
    .sidebar nav a.active { border-left: none; border-bottom-color: var(--primary); }
    .sidebar-footer { display: none; }
    main { padding: 18px; }
}
