:root {
    --bg: #f4f6fa;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #e3e8ef;
    --text: #1a2230;
    --text-soft: #5b6878;
    --muted: #8b97a8;
    --accent: #2f6df0;
    --accent-soft: #e8f0fe;
    --green: #16a34a;
    --green-soft: #e6f6ec;
    --red: #dc2626;
    --red-soft: #fdeaea;
    --amber: #d97706;
    --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px rgba(16, 24, 40, .06);
    --radius: 12px;
}

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

/* The `hidden` attribute must always beat a class's `display` (e.g. the modal overlay). */
[hidden] { display: none !important; }

body {
    font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ---------- Login ---------- */
.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, #eef2fb, #f6f8fc 60%, #eaf0fe);
    padding: 24px;
}
.login-card {
    width: 100%;
    max-width: 380px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow);
    padding: 32px 28px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.login-brand { text-align: center; margin-bottom: 8px; }
.login-logo {
    width: 48px; height: 48px; margin: 0 auto 12px;
    display: grid; place-items: center;
    background: var(--accent); color: #fff;
    border-radius: 12px; font-size: 22px;
}
.login-brand h1 { font-size: 20px; }
.login-brand p { color: var(--muted); font-size: 13px; margin-top: 4px; }

label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 500; color: var(--text-soft); }
input, select, textarea {
    font: inherit; color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 9px 11px;
    width: 100%;
    transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { resize: vertical; min-height: 60px; }

/* ---------- Buttons ---------- */
.btn {
    font: inherit; font-weight: 600;
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 9px 14px;
    cursor: pointer;
    display: inline-flex; align-items: center; gap: 6px;
    transition: background .15s, border-color .15s, opacity .15s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #245fd6; }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text-soft); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--red-soft); color: var(--red); }
.btn-danger:hover { background: #fbdcdc; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-block { width: 100%; justify-content: center; }

/* ---------- App shell ---------- */
.app { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }

.sidebar {
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
    padding: 18px 14px;
    position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 18px; }
.brand-logo {
    width: 30px; height: 30px; display: grid; place-items: center;
    background: var(--accent); color: #fff; border-radius: 8px; font-size: 15px;
}
.brand-name { font-weight: 700; font-size: 15px; }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
    text-align: left; font: inherit; font-weight: 500;
    background: transparent; border: none; color: var(--text-soft);
    padding: 10px 12px; border-radius: 8px; cursor: pointer;
    transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.sidebar-foot { border-top: 1px solid var(--border); padding-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 2px 4px; }
.user-avatar {
    width: 34px; height: 34px; border-radius: 50%;
    background: var(--accent); color: #fff;
    display: grid; place-items: center; font-weight: 600; font-size: 13px;
}
.user-name { font-weight: 600; font-size: 13px; }
.user-role { font-size: 11.5px; color: var(--muted); text-transform: capitalize; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 18px 28px; border-bottom: 1px solid var(--border);
    background: var(--surface); position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: 19px; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.content { padding: 24px 28px; }

/* ---------- Cards / stats ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; margin-bottom: 22px; }
.stat-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
}
.stat-label { font-size: 12.5px; color: var(--muted); font-weight: 500; display: flex; align-items: center; gap: 6px; }
.stat-value { font-size: 24px; font-weight: 700; margin-top: 8px; letter-spacing: -.3px; }
.stat-sub { font-size: 12px; color: var(--text-soft); margin-top: 4px; }
.stat-value.pos { color: var(--green); }
.stat-value.neg { color: var(--red); }

.panel {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow);
    margin-bottom: 22px; overflow: hidden;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.panel-head h2 { font-size: 15px; }
.panel-body { padding: 4px 0; }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; }
thead th {
    text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px;
    color: var(--muted); font-weight: 600; padding: 11px 18px; border-bottom: 1px solid var(--border);
}
tbody td { padding: 12px 18px; border-bottom: 1px solid var(--border); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

.tag { display: inline-flex; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.tag-green { background: var(--green-soft); color: var(--green); }
.tag-blue { background: var(--accent-soft); color: var(--accent); }
.tag-gray { background: #eef1f5; color: var(--text-soft); }
.tag-amber { background: #fdf0dc; color: var(--amber); }

.pos { color: var(--green); }
.neg { color: var(--red); }
.muted-text { color: var(--muted); }

.empty { text-align: center; padding: 40px 20px; color: var(--muted); }

/* ---------- Forms in modal ---------- */
.modal-backdrop {
    position: fixed; inset: 0; background: rgba(16, 24, 40, .45);
    display: grid; place-items: center; z-index: 50; padding: 20px;
}
.modal {
    background: var(--surface); border-radius: 14px; width: 100%; max-width: 480px;
    box-shadow: 0 20px 60px rgba(16, 24, 40, .25); max-height: 90vh; overflow: auto;
}
.modal-head { padding: 18px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-head h3 { font-size: 16px; }
.modal-body { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.checkbox-row { flex-direction: row; align-items: center; gap: 8px; }
.checkbox-row input { width: auto; }
.close-x { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--muted); line-height: 1; }

.form-error { background: var(--red-soft); color: var(--red); padding: 9px 12px; border-radius: 8px; font-size: 13px; }
.form-hint { font-size: 12px; color: var(--muted); }

.toast {
    position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
    background: var(--text); color: #fff; padding: 11px 18px; border-radius: 9px;
    font-size: 13px; font-weight: 500; z-index: 80; box-shadow: var(--shadow);
}
.toast.error { background: var(--red); }

/* Developer assignment (project modal) */
.dev-assign { border: 1px solid var(--border); border-radius: 10px; padding: 12px; background: var(--surface-2); display: flex; flex-direction: column; gap: 10px; }
.dev-assign-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; }
#devRows { display: flex; flex-direction: column; gap: 8px; }
.dev-row { display: grid; grid-template-columns: 1fr 120px auto; gap: 8px; align-items: center; }
.dev-row select, .dev-row input { padding: 7px 9px; }
.dev-chips { display: flex; flex-wrap: wrap; gap: 4px; justify-content: flex-end; margin-top: 4px; }
.dev-chip { background: var(--accent-soft); color: var(--accent); border-radius: 6px; padding: 1px 7px; font-size: 11px; font-weight: 600; }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 18px; }
.toolbar input[type=date] { width: auto; }
.spacer { flex: 1; }

@media (max-width: 820px) {
    .app { grid-template-columns: 1fr; }
    .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; }
    .nav { flex-direction: row; flex-wrap: wrap; }
    .sidebar-foot { border: none; flex-direction: row; }
    .field-row { grid-template-columns: 1fr; }
}
