/* ===========================================================
   Kalvi Profiles — application styles
   =========================================================== */

:root {
    --bg: #f4f6fb;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #e3e8f0;
    --text: #12151c;
    --muted: #6b7488;
    --brand: #3b5bfd;
    --brand-dark: #2c46d6;
    --brand-soft: #eaeeff;
    --good: #12805c;
    --good-soft: #e3f6ee;
    --warn: #a2610a;
    --warn-soft: #fdf0dc;
    --danger: #c02b2b;
    --danger-soft: #fdeaea;
    --sidebar: #12172a;
    --sidebar-text: #aab3ca;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 8px 24px rgba(16, 24, 40, .06);
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
    margin: 0;
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }

code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: .85em;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 5px;
    padding: 1px 6px;
}

.muted { color: var(--muted); }
.block { display: block; }
.ta-right { text-align: right; }
.icon { width: 18px; height: 18px; flex: 0 0 auto; }

/* ---------- Shell ---------- */

.shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 248px;
    flex: 0 0 248px;
    background: var(--sidebar);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    padding: 20px 14px;
    position: sticky;
    top: 0;
    height: 100vh;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 22px; }

.brand-mark {
    width: 34px; height: 34px;
    display: grid; place-items: center;
    border-radius: 9px;
    background: var(--brand);
    color: #fff;
    font-weight: 700;
}
.brand-mark.lg { width: 46px; height: 46px; font-size: 20px; border-radius: 12px; }
.brand-text { color: #fff; font-weight: 650; font-size: 15px; }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }

.nav-item {
    display: flex; align-items: center; gap: 11px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: var(--sidebar-text);
    font-size: 14px;
    font-weight: 500;
    transition: background .15s, color .15s;
}
.nav-item:hover { background: rgba(255, 255, 255, .06); color: #fff; text-decoration: none; }
.nav-item.is-active { background: var(--brand); color: #fff; }

.nav-button {
    width: 100%;
    background: none; border: 0; cursor: pointer;
    font-family: inherit; text-align: left;
}

.sidebar-foot { border-top: 1px solid rgba(255, 255, 255, .08); padding-top: 10px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    display: flex; align-items: center; gap: 14px;
    padding: 14px 26px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 20;
}
.page-title { font-size: 18px; flex: 1; }
.topbar-user { display: flex; align-items: center; gap: 10px; }
.avatar {
    width: 36px; height: 36px;
    display: grid; place-items: center;
    border-radius: 50%;
    background: var(--brand-soft);
    color: var(--brand-dark);
    font-weight: 700;
}
.who { display: flex; flex-direction: column; line-height: 1.25; }
.who small { color: var(--muted); font-size: 12px; }

.content { flex: 1; padding: 24px 26px 40px; display: flex; flex-direction: column; gap: 18px; }

.site-footer {
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    flex-wrap: wrap;
    padding: 16px 26px;
    border-top: 1px solid var(--border);
    background: var(--surface);
    color: var(--muted);
    font-size: 13px;
}
.site-footer a { color: var(--brand); }

.burger { display: none; }

/* ---------- Plain pages (login / errors) ---------- */

.plain { background: linear-gradient(160deg, #12172a 0%, #263063 55%, #3b5bfd 140%); }
.plain-wrap {
    min-height: 100vh;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    padding: 32px 18px;
    gap: 18px;
}
.plain-card {
    width: 100%; max-width: 400px;
    background: var(--surface);
    border-radius: 16px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, .25);
    padding: 30px 28px;
}
.plain-footer { color: rgba(255, 255, 255, .78); font-size: 13px; }
.plain-footer a { color: #fff; text-decoration: underline; }

.auth-head { text-align: center; margin-bottom: 22px; display: grid; justify-items: center; gap: 6px; }
.auth-head h1 { font-size: 20px; }
.auth-head p { margin: 0; color: var(--muted); font-size: 14px; }

.error-card { max-width: 460px; text-align: center; }
.error-code { font-size: 44px; font-weight: 700; color: var(--brand); margin: 0; }

/* ---------- Cards ---------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
}
.card-title { font-size: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; gap: 12px; }
.table-card { padding: 0; overflow: hidden; }
.empty { text-align: center; display: grid; gap: 10px; justify-items: center; padding: 42px 20px; }

.notice-card { display: flex; gap: 14px; align-items: flex-start; border-left: 3px solid var(--brand); }
.notice-card .icon { width: 22px; height: 22px; color: var(--brand); margin-top: 2px; }
.notice-card h2 { font-size: 15px; margin-bottom: 2px; }
.notice-card p { margin: 0; font-size: 14px; }
.notice-card.success { border-left-color: var(--good); }
.notice-card.success .icon { color: var(--good); }

.split { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }

/* ---------- Stats ---------- */

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.stat {
    display: flex; flex-direction: column; gap: 4px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px;
    color: inherit;
}
.stat:hover { text-decoration: none; border-color: var(--brand); }
.stat-label { font-size: 13px; color: var(--muted); }
.stat-value { font-size: 28px; line-height: 1.1; font-weight: 700; }
.stat-foot { font-size: 12px; color: var(--muted); }
.stat-good .stat-value { color: var(--good); }
.stat-warn .stat-value { color: var(--warn); }

.progress-head { display: flex; justify-content: space-between; align-items: baseline; }
.progress-pct { font-weight: 700; font-size: 18px; }
.progress { height: 9px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin: 10px 0 8px; }
.progress span { display: block; height: 100%; background: var(--brand); border-radius: 99px; }
.progress-card p { margin: 0; font-size: 13px; }

.mini-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.mini-list li + li { border-top: 1px solid var(--border); }
.mini-list a {
    display: flex; justify-content: space-between; align-items: center; gap: 10px;
    padding: 10px 2px; color: inherit;
}
.mini-list a:hover { text-decoration: none; color: var(--brand); }
.mini-list small { color: var(--muted); font-size: 12px; white-space: nowrap; }

/* ---------- Forms ---------- */

.form { display: flex; flex-direction: column; gap: 16px; }
.form.narrow { max-width: 680px; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field.inline { flex: 0 1 220px; }
.field.grow { flex: 1 1 280px; }
.field-label { font-size: 13px; font-weight: 600; color: #333c50; }
.req { color: var(--danger); font-style: normal; margin-left: 2px; }
.hint { font-size: 12px; color: var(--muted); }
.error-text { font-size: 12px; color: var(--danger); font-weight: 500; }

input[type=text], input[type=email], input[type=tel], input[type=url], input[type=number],
input[type=date], input[type=password], input[type=search], input[type=file], select, textarea {
    width: 100%;
    font: inherit;
    font-size: 14px;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 9px 11px;
    transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(59, 91, 253, .14);
}
input[readonly], select:disabled, input:disabled { background: var(--surface-2); color: var(--muted); }

.has-error input, .has-error select, .has-error textarea { border-color: var(--danger); }

.password-wrap { position: relative; display: block; }
.password-wrap input { padding-right: 62px; }
.reveal {
    position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
    background: none; border: 0; cursor: pointer;
    font: inherit; font-size: 12px; font-weight: 600;
    color: var(--brand); padding: 4px 6px;
}

.choice-list { display: flex; flex-direction: column; gap: 8px; }
.choice { display: flex; align-items: flex-start; gap: 9px; font-size: 14px; cursor: pointer; }
.choice input { margin-top: 3px; accent-color: var(--brand); }

.switch-set { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px; display: grid; gap: 10px; }
.switch-set legend { padding: 0 6px; }
.switch { display: flex; align-items: center; gap: 9px; font-size: 14px; cursor: pointer; }
.switch input { accent-color: var(--brand); width: 16px; height: 16px; }

.confirm-box {
    background: var(--brand-soft);
    border: 1px solid #d3dbff;
    border-radius: var(--radius-sm);
    padding: 14px;
}

.form-actions { display: flex; gap: 10px; justify-content: flex-end; align-items: center; flex-wrap: wrap; }

.inline-note {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font-size: 13px;
}

.range-pair { display: flex; gap: 6px; }

/* ---------- Buttons ---------- */

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    font: inherit; font-size: 14px; font-weight: 600;
    padding: 9px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    transition: background .15s, border-color .15s, color .15s;
    white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-ghost { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-ghost:hover { border-color: var(--brand); color: var(--brand); }
.btn-danger { background: var(--danger-soft); color: var(--danger); border-color: #f4cccc; }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-block { width: 100%; }

.icon-button {
    display: inline-grid; place-items: center;
    width: 32px; height: 32px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--muted);
    cursor: pointer;
}
.icon-button:hover { color: var(--brand); border-color: var(--brand); text-decoration: none; }
.icon-button.danger:hover { color: var(--danger); border-color: var(--danger); }

.row-actions { display: inline-flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.inline-form { display: inline; }

.link { font-weight: 500; }

/* ---------- Toolbar & filters ---------- */

.toolbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.toolbar-copy p { margin: 2px 0 0; font-size: 13px; }

.filters-card { display: flex; flex-direction: column; gap: 14px; }
.filters-head { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.filter-row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.filter-actions { display: flex; gap: 8px; align-items: center; }
.filter-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 12px;
    border-top: 1px dashed var(--border);
    padding-top: 14px;
}
.filter-grid .field.inline { flex: 1 1 auto; }

/* ---------- Tables ---------- */

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

.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { padding: 11px 14px; text-align: left; vertical-align: middle; }
.table thead th {
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    font-size: 12px;
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
    white-space: nowrap;
}
.table tbody tr + tr td { border-top: 1px solid var(--border); }
.table tbody tr:hover { background: var(--surface-2); }
.empty-cell { text-align: center; color: var(--muted); padding: 34px 14px; }

.th-sort { color: inherit; display: inline-flex; gap: 5px; align-items: center; white-space: nowrap; }
.th-sort:hover { color: var(--brand); text-decoration: none; }
.th-sort .caret { opacity: .45; font-size: 10px; }
.th-sort.is-on { color: var(--brand); }
.th-sort.is-on .caret { opacity: 1; }

.sticky-col { position: sticky; left: 0; background: var(--surface); z-index: 2; }
.table thead .sticky-col { background: var(--surface-2); z-index: 3; }
.table tbody tr:hover .sticky-col { background: var(--surface-2); }

.tag {
    display: inline-block;
    font-size: 11.5px; font-weight: 600;
    padding: 2px 9px;
    border-radius: 99px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--muted);
    white-space: nowrap;
}
.tag-good { background: var(--good-soft); color: var(--good); border-color: #c6ecdd; }
.tag-warn { background: var(--warn-soft); color: var(--warn); border-color: #f4dcb6; }
.tag-accent { background: var(--brand-soft); color: var(--brand-dark); border-color: #d3dbff; }
.tag-muted { background: var(--surface-2); }

.thumb { max-width: 120px; max-height: 90px; border-radius: var(--radius-sm); border: 1px solid var(--border); }

/* ---------- Detail list ---------- */

.detail-list { margin: 0; display: grid; gap: 0; }
.detail-row {
    display: grid;
    grid-template-columns: 240px 1fr;
    gap: 16px;
    padding: 11px 0;
}
.detail-row + .detail-row { border-top: 1px solid var(--border); }
.detail-row dt { font-weight: 600; font-size: 14px; color: #333c50; }
.detail-row dd { margin: 0; font-size: 14px; word-break: break-word; }

/* ---------- Drag & drop ---------- */

.sortable-table tbody tr { cursor: default; }
.sortable-table tbody tr.dragging { opacity: .4; }
.sortable-table tbody tr.drop-target td { box-shadow: inset 0 2px 0 var(--brand); }
.w-drag { width: 42px; }
.w-order { width: 46px; color: var(--muted); }
.drag-handle {
    display: inline-grid; place-items: center;
    width: 28px; height: 28px;
    border-radius: 6px;
    color: var(--muted);
    cursor: grab;
}
.drag-handle:hover { background: var(--surface-2); color: var(--brand); }
.drag-handle:active { cursor: grabbing; }

.reorder-status {
    padding: 9px 16px;
    font-size: 13px;
    font-weight: 500;
    background: var(--brand-soft);
    color: var(--brand-dark);
    border-bottom: 1px solid var(--border);
}
.reorder-status.is-error { background: var(--danger-soft); color: var(--danger); }
.reorder-status.is-done { background: var(--good-soft); color: var(--good); }

.preview-card { display: flex; flex-direction: column; gap: 12px; }
.preview-card p { margin: 0; font-size: 13px; }
.preview-field { display: flex; flex-direction: column; gap: 6px; }
.preview-input {
    border: 1px dashed var(--border);
    border-radius: var(--radius-sm);
    padding: 9px 11px;
    font-size: 13px;
    color: var(--muted);
    background: var(--surface-2);
}

/* ---------- Pagination ---------- */

.pager {
    display: flex; align-items: center; justify-content: space-between; gap: 14px;
    flex-wrap: wrap;
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    background: var(--surface-2);
    font-size: 13px;
}
.pager-count { margin: 0; color: var(--muted); }
.pager-links { display: flex; gap: 4px; align-items: center; }
.pager-link {
    min-width: 32px; height: 32px;
    display: inline-grid; place-items: center;
    padding: 0 9px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-weight: 500;
}
.pager-link:hover { border-color: var(--brand); color: var(--brand); text-decoration: none; }
.pager-link.is-current { background: var(--brand); border-color: var(--brand); color: #fff; }
.pager-link.is-disabled { opacity: .45; pointer-events: none; }
.pager-gap { color: var(--muted); padding: 0 2px; }
.pager-size { display: flex; align-items: center; }
.pager-size label { display: flex; align-items: center; gap: 7px; color: var(--muted); }
.pager-size select { padding: 5px 8px; font-size: 13px; width: auto; }

/* ---------- Flash ---------- */

.flash-stack { display: flex; flex-direction: column; gap: 8px; }
.flash {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 11px 14px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    border: 1px solid;
}
.flash-success { background: var(--good-soft); color: var(--good); border-color: #c6ecdd; }
.flash-error { background: var(--danger-soft); color: var(--danger); border-color: #f4cccc; }
.flash-info { background: var(--brand-soft); color: var(--brand-dark); border-color: #d3dbff; }
.flash-close { background: none; border: 0; font-size: 19px; line-height: 1; cursor: pointer; color: inherit; opacity: .6; }
.flash-close:hover { opacity: 1; }

/* ---------- Responsive ---------- */

@media (max-width: 1080px) {
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    .split { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
    .sidebar {
        position: fixed; z-index: 60; left: 0; top: 0;
        transform: translateX(-100%);
        transition: transform .2s ease;
        box-shadow: 0 0 40px rgba(0, 0, 0, .3);
    }
    .sidebar.is-open { transform: translateX(0); }
    .burger { display: inline-grid; }
    .content { padding: 18px 16px 32px; }
    .topbar { padding: 12px 16px; }
    .form-grid, .form-grid.two { grid-template-columns: 1fr; }
    .detail-row { grid-template-columns: 1fr; gap: 3px; }
    .who { display: none; }
    .site-footer { padding: 14px 16px; }
}

@media (max-width: 560px) {
    .stat-grid { grid-template-columns: 1fr; }
    .toolbar { align-items: stretch; }
    .filters-head, .filter-row { flex-direction: column; align-items: stretch; }
    .field.inline, .field.grow { flex: 1 1 auto; }
}
