:root {
    --bg: #0f1220;
    --surface: #171a2b;
    --surface-2: #1e2238;
    --border: #2a2f4a;
    --text: #e8eaf2;
    --muted: #9aa0b8;
    --primary: #6366f1;
    --primary-2: #818cf8;
    --green: #22c55e;
    --amber: #f59e0b;
    --red: #ef4444;
    --radius: 12px;
    --shadow: 0 8px 30px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }

/* The `hidden` attribute must always win, even over display:grid/flex/inline-flex
   set below (otherwise the modal overlay & collapsed sections stay visible and
   the modal eats every click). */
[hidden] { display: none !important; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: radial-gradient(1200px 600px at 80% -10%, #1a1f3a 0%, var(--bg) 60%);
    color: var(--text);
    min-height: 100vh;
}

h1, h2, h3 { margin: 0 0 .4rem; font-weight: 650; }
.muted { color: var(--muted); }
.small { font-size: .8rem; }
a { color: var(--primary-2); text-decoration: none; }

/* ---------- Topbar ---------- */
.topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: .85rem 1.4rem;
    background: rgba(23,26,43,.8);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: .7rem; }
.brand strong { display: block; line-height: 1.1; }
.brand .muted { display: block; }
.logo-dot {
    width: 30px; height: 30px; border-radius: 9px;
    background: linear-gradient(135deg, var(--primary), var(--primary-2));
    box-shadow: 0 0 18px rgba(99,102,241,.6);
}
.topbar-right { display: flex; align-items: center; gap: .6rem; }
.user-chip { display: flex; align-items: center; gap: .5rem; font-size: .9rem; }
.avatar {
    width: 28px; height: 28px; border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--primary-2));
    display: grid; place-items: center; font-weight: 700; font-size: .8rem;
}

/* ---------- Layout ---------- */
.container { max-width: 1080px; margin: 1.4rem auto; padding: 0 1rem; display: grid; gap: 1.4rem; }
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.2rem 1.3rem;
    box-shadow: var(--shadow);
}
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; gap: 1rem; }
.panel-tools { display: flex; align-items: center; gap: .8rem; }

/* ---------- Forms ---------- */
.entry-form label, .login-card label { display: block; font-size: .82rem; color: var(--muted); margin-bottom: .9rem; }
.entry-form .grid {
    display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 1rem;
}
label.full, label.req { }
label.req::after { content: " *"; color: var(--primary-2); }
input, select, textarea {
    width: 100%; margin-top: .35rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 9px;
    padding: .6rem .7rem;
    font-size: .92rem;
    font-family: inherit;
}
input:focus, select:focus, textarea:focus {
    outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99,102,241,.2);
}
textarea { resize: vertical; }

.check-field { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding-top: 1.4rem; }
.check-field.inline { justify-content: flex-start; padding-top: 0; }
.check-field > span:first-child { color: var(--text); }

.link-btn {
    background: none; border: none; color: var(--primary-2); cursor: pointer;
    padding: 0; font-size: .85rem; margin-bottom: .9rem;
}
.location-grid { grid-template-columns: repeat(3, 1fr) !important; }
.form-actions { margin-top: .4rem; display: flex; gap: .6rem; }

/* ---------- Switch ---------- */
.switch { position: relative; display: inline-block; width: 46px; height: 26px; margin: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute; inset: 0; cursor: pointer;
    background: var(--surface-2); border: 1px solid var(--border);
    border-radius: 30px; transition: .2s;
}
.slider::before {
    content: ""; position: absolute; height: 18px; width: 18px; left: 3px; top: 3px;
    background: var(--muted); border-radius: 50%; transition: .2s;
}
.switch input:checked + .slider { background: var(--green); border-color: var(--green); }
.switch input:checked + .slider::before { transform: translateX(20px); background: #fff; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; gap: .4rem;
    border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
    padding: .55rem .9rem; border-radius: 9px; cursor: pointer; font-size: .88rem;
    font-family: inherit; transition: .15s; text-decoration: none;
}
.btn:hover { border-color: var(--primary); }
.btn.primary { background: linear-gradient(135deg, var(--primary), var(--primary-2)); border: none; color: #fff; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.danger { border-color: var(--red); color: #fda4a4; }
.btn.danger:hover { background: rgba(239,68,68,.12); }
.btn.small { padding: .35rem .65rem; font-size: .8rem; }
.btn.block { width: 100%; justify-content: center; }
.icon-btn { background: none; border: none; color: var(--muted); font-size: 1.4rem; cursor: pointer; line-height: 1; }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { text-align: left; padding: .65rem .7rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; }
tbody tr:hover { background: rgba(255,255,255,.02); }
td.empty { text-align: center; color: var(--muted); padding: 2rem; }
.col-actions { text-align: right; }
.row-actions { display: flex; gap: .35rem; justify-content: flex-end; }

/* ---------- Badges / tags ---------- */
.badge { display: inline-block; padding: .18rem .55rem; border-radius: 20px; font-size: .74rem; font-weight: 600; }
.badge.green { background: rgba(34,197,94,.15); color: #86efac; }
.badge.amber { background: rgba(245,158,11,.15); color: #fcd34d; }
.badge.red   { background: rgba(239,68,68,.15); color: #fca5a5; }
.badge.blue  { background: rgba(99,102,241,.18); color: #c7d2fe; }
.badge.gray  { background: rgba(154,160,184,.15); color: var(--muted); }
.tick { color: var(--green); font-weight: 700; }
.tag { padding: .1rem .4rem; border-radius: 6px; font-size: .68rem; text-transform: uppercase; letter-spacing: .03em; }
.admin-tag { background: rgba(99,102,241,.2); color: #c7d2fe; }
.readonly-tag { background: rgba(154,160,184,.15); color: var(--muted); }

/* ---------- Modal ---------- */
.modal {
    position: fixed; inset: 0; background: rgba(6,8,18,.7);
    display: grid; place-items: center; z-index: 50; padding: 1rem;
}
.modal-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); width: min(560px, 100%); box-shadow: var(--shadow);
    max-height: 90vh; overflow: auto;
}
.modal-head, .modal-foot { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1.2rem; }
.modal-head { border-bottom: 1px solid var(--border); }
.modal-foot { border-top: 1px solid var(--border); gap: .5rem; justify-content: flex-end; }
.modal-body { padding: 1.2rem; }
.detail-grid { display: grid; grid-template-columns: 150px 1fr; gap: .6rem 1rem; }
.detail-grid dt { color: var(--muted); font-size: .82rem; }
.detail-grid dd { margin: 0; }

/* ---------- Login ---------- */
.login-body { display: grid; place-items: center; }
.login-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 16px; padding: 2rem; width: min(370px, 92vw); box-shadow: var(--shadow);
    margin-top: 8vh;
}
.login-brand { text-align: center; margin-bottom: 1.5rem; }
.login-brand .logo-dot { margin: 0 auto .7rem; width: 40px; height: 40px; }
.login-hint { text-align: center; margin-top: 1rem; }
.alert { padding: .6rem .8rem; border-radius: 8px; margin-bottom: 1rem; font-size: .85rem; }
.alert.error { background: rgba(239,68,68,.15); color: #fca5a5; border: 1px solid rgba(239,68,68,.3); }

/* ---------- Misc ---------- */
.chips { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem; }
.chip { background: var(--surface-2); border: 1px solid var(--border); padding: .3rem .7rem; border-radius: 20px; font-size: .82rem; }
.inline-form { display: flex; gap: .5rem; max-width: 340px; }
.inline-form input { margin-top: 0; }
.stat-row { display: flex; gap: 1rem; flex-wrap: wrap; }
.stat { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 1rem 1.4rem; text-align: center; min-width: 120px; }
.stat-num { display: block; font-size: 1.8rem; font-weight: 700; color: var(--primary-2); }

.toast {
    position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%);
    background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
    padding: .7rem 1.1rem; border-radius: 10px; box-shadow: var(--shadow); z-index: 100; font-size: .88rem;
}
.toast.ok { border-color: var(--green); }
.toast.err { border-color: var(--red); }

@media (max-width: 620px) {
    .entry-form .grid, .location-grid { grid-template-columns: 1fr !important; }
    .detail-grid { grid-template-columns: 1fr; }
    .detail-grid dt { margin-top: .5rem; }
}
