@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
    --brand: #0f4c81;
    --brand-dark: #0b3a63;
    --brand-light: #e8f1fa;
    --accent: #c9a227;
    --ink: #1a2233;
    --ink-soft: #5b6472;
    --ink-faint: #8792a0;
    --border: #e3e7ed;
    --bg: #f3f5f8;
    --surface: #ffffff;
    --success: #1f8a5a;
    --success-bg: #e6f6ee;
    --danger: #c0392b;
    --danger-bg: #fdecea;
    --radius: 10px;
    --radius-lg: 14px;
    --shadow: 0 1px 2px rgba(15, 30, 60, .05), 0 4px 14px rgba(15, 30, 60, .06);
    --shadow-sm: 0 1px 2px rgba(15, 30, 60, .06);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, Roboto, Arial, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    background: var(--bg);
    margin: 0;
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3 { font-family: inherit; }

a { color: var(--brand); }

::selection { background: var(--brand-light); color: var(--brand-dark); }

:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

.topbar {
    background: linear-gradient(120deg, var(--brand) 0%, var(--brand-dark) 100%);
    color: #fff;
    padding: 20px 32px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    box-shadow: 0 2px 16px rgba(11, 58, 99, .18);
    position: relative;
}

.topbar .brand {
    display: flex;
    align-items: center;
    gap: 14px;
}

.topbar .brand-mark {
    width: 40px; height: 40px;
    border-radius: 10px;
    background: rgba(255,255,255,.16);
    border: 1px solid rgba(255,255,255,.18);
    display: flex; align-items: center; justify-content: center;
    font-weight: 800; font-size: .95rem;
    letter-spacing: .02em;
}

.topbar h1 {
    font-size: 1.2rem;
    margin: 0;
    font-weight: 700;
    letter-spacing: -.01em;
}

.topbar .sub {
    font-size: .78rem;
    opacity: .8;
    margin-top: 2px;
    font-weight: 500;
}

.container {
    max-width: 1180px;
    margin: 0 auto;
    padding: 24px 20px 60px;
}

.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 14px;
    margin-bottom: 22px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px 20px;
    box-shadow: var(--shadow-sm);
    transition: box-shadow .15s, transform .15s;
}
.stat-card:hover { box-shadow: var(--shadow); transform: translateY(-1px); }

.stat-card .num { font-size: 1.7rem; font-weight: 800; color: var(--brand); line-height: 1.15; letter-spacing: -.02em; }
.stat-card .lbl { font-size: .72rem; color: var(--ink-soft); margin-top: 5px; text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }

.toolbar {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 18px;
}

.search-box {
    flex: 1;
    min-width: 220px;
    display: flex;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}

.search-box input {
    flex: 1;
    border: none;
    padding: 10px 14px;
    font-size: .9rem;
    outline: none;
    background: transparent;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 18px;
    border-radius: 8px;
    border: 1px solid transparent;
    font-size: .86rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    text-decoration: none;
    transition: background .15s, border-color .15s, transform .05s, box-shadow .15s;
    white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); color: #fff; box-shadow: 0 1px 2px rgba(15,76,129,.25); }
.btn-primary:hover { background: var(--brand-dark); }
.btn-secondary { background: var(--surface); color: var(--brand); border-color: var(--border); }
.btn-secondary:hover { background: var(--brand-light); border-color: var(--brand); }
.btn-danger { background: var(--surface); color: var(--danger); border-color: #f3d3ce; }
.btn-danger:hover { background: var(--danger-bg); }
.btn-sm { padding: 6px 12px; font-size: .78rem; }
.btn-gold { background: var(--accent); color: #3a2f05; box-shadow: 0 1px 2px rgba(201,162,39,.3); }
.btn-gold:hover { filter: brightness(.95); }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 13px 16px; font-size: .87rem; border-bottom: 1px solid var(--border); }
th { background: #f8fafc; font-weight: 700; color: var(--ink-soft); font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; }
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background .1s; }
tbody tr:hover td { background: #fafbfd; }

.avatar {
    width: 40px; height: 40px; border-radius: 50%;
    object-fit: cover;
    border: 1px solid var(--border);
    background: var(--brand-light);
    display: inline-flex; align-items: center; justify-content: center;
    font-size: .78rem; font-weight: 700; color: var(--brand);
    vertical-align: middle;
    flex-shrink: 0;
}

.name-cell { display: flex; align-items: center; gap: 10px; }
.name-cell .sub { font-size: .76rem; color: var(--ink-soft); }

.pill {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: .74rem;
    font-weight: 600;
}
.pill-ok { background: var(--success-bg); color: var(--success); }
.pill-neutral { background: var(--brand-light); color: var(--brand); }

.empty-state { text-align: center; padding: 60px 20px; color: var(--ink-soft); }
.empty-state .icon { font-size: 2.2rem; margin-bottom: 10px; }

.actions-cell { display: flex; gap: 6px; justify-content: flex-end; }

.table-wrap { overflow-x: auto; }

/* Form page */
.form-header {
    display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px;
    margin-bottom: 18px;
}
.back-link { font-size: .82rem; color: var(--brand); text-decoration: none; font-weight: 600; display: inline-flex; align-items: center; gap: 4px; }
.back-link:hover { text-decoration: underline; }

fieldset.section {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    padding: 22px 24px 24px;
    margin: 0 0 18px;
    transition: box-shadow .15s;
}
fieldset.section:focus-within { box-shadow: var(--shadow); }
fieldset.section legend {
    padding: 0 10px;
    font-size: .78rem;
    font-weight: 700;
    color: var(--brand);
    text-transform: uppercase;
    letter-spacing: .05em;
}
.field-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px 20px; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: .78rem; font-weight: 600; color: var(--ink-soft); }
.field input[type=text], .field input[type=date], .field input[type=email],
.field textarea, .field select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 7px;
    font-size: .92rem;
    font-family: inherit;
    background: #fff;
    color: var(--ink);
    transition: border-color .15s, box-shadow .15s;
    -webkit-appearance: none;
    appearance: none;
}
.field input:focus, .field textarea:focus, .field select:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--brand-light);
}
.field textarea { min-height: 68px; resize: vertical; }

.file-field {
    border: 1.5px dashed var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    background: #fafbfd;
    transition: border-color .15s, background .15s;
}
.file-field:focus-within { border-color: var(--brand); background: var(--brand-light); }
.file-field input[type=file] { font-size: .8rem; flex: 1; min-width: 140px; color: var(--ink-soft); }
.file-field input[type=file]::file-selector-button {
    padding: 7px 14px;
    margin-right: 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fff;
    color: var(--brand);
    font-size: .8rem;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s;
}
.file-field input[type=file]::file-selector-button:hover { background: var(--brand-light); }
.file-thumb { width: 44px; height: 44px; border-radius: 6px; object-fit: cover; border: 1px solid var(--border); flex-shrink: 0; }
.file-current { font-size: .76rem; color: var(--ink-soft); display: block; margin-top: 2px; word-break: break-all; }
.file-current a { color: var(--brand); text-decoration: none; }
.file-current a:hover { text-decoration: underline; }

.sticky-save {
    position: sticky;
    bottom: 0;
    background: rgba(245,247,250,.94);
    backdrop-filter: blur(6px);
    padding: 14px 4px;
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    border-top: 1px solid var(--border);
    margin-top: 6px;
}

/* Tablet */
@media (max-width: 860px) {
    .container { padding: 20px 16px 56px; }
    .stats-row { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
}

/* Mobile */
@media (max-width: 640px) {
    body { font-size: 15px; }
    .container { padding: 14px 12px 90px; }
    .topbar { padding: 14px 16px; }
    .topbar h1 { font-size: 1.05rem; }
    .topbar .sub { font-size: .72rem; }
    .stats-row { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .stat-card { padding: 12px 14px; }
    .stat-card .num { font-size: 1.35rem; }
    .toolbar { flex-direction: column; align-items: stretch; }
    .toolbar .btn, .toolbar .search-box { width: 100%; }
    .field-grid { grid-template-columns: 1fr; gap: 14px; }
    fieldset.section { padding: 16px 14px 18px; margin-bottom: 12px; }
    fieldset.section legend { font-size: .76rem; }
    .field input, .field textarea, .field select { font-size: 16px; } /* prevents iOS zoom-on-focus */
    .sticky-save { flex-direction: column-reverse; padding: 12px; position: fixed; left: 0; right: 0; bottom: 0; box-shadow: 0 -2px 8px rgba(0,0,0,.06); margin-top: 0; }
    .sticky-save .btn { width: 100%; justify-content: center; }
    table { font-size: .8rem; }
    th, td { padding: 9px 8px; }
    .actions-cell { flex-wrap: wrap; justify-content: flex-start; }
    .name-cell .sub { display: block; }
}

/* Small phones */
@media (max-width: 380px) {
    .stats-row { grid-template-columns: 1fr; }
}
