/* ---------- Theme tokens ---------- */
:root {
    --bg: #f3f4f8;
    --surface: #ffffff;
    --surface-alt: #f8f9fc;
    --border: #e2e4ec;
    --text: #1a1d29;
    --text-muted: #6b7080;
    --primary: #4f5fea;
    --primary-hover: #3d4bd6;
    --success: #16a34a;
    --success-bg: #ecfdf3;
    --error: #dc2626;
    --error-bg: #fef2f2;
    --warning-bg: #fff8e1;
    --warning-border: #f0d868;
    --badge: #dc2626;
    --shadow: 0 1px 3px rgba(20,22,40,0.06), 0 1px 2px rgba(20,22,40,0.04);
    --shadow-md: 0 4px 14px rgba(20,22,40,0.08);
    --radius: 10px;
}
:root[data-theme="dark"] {
    --bg: #14151f;
    --surface: #1c1e2b;
    --surface-alt: #22243333;
    --surface-alt: #242637;
    --border: #33364a;
    --text: #e7e8f0;
    --text-muted: #9498ab;
    --primary: #7c87f5;
    --primary-hover: #939ef7;
    --success: #34d399;
    --success-bg: #103322;
    --error: #f87171;
    --error-bg: #3a1a1a;
    --warning-bg: #3a331a;
    --warning-border: #6b5d20;
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 6px 20px rgba(0,0,0,0.35);
}

* { box-sizing: border-box; }
html { color-scheme: light; }
html[data-theme="dark"] { color-scheme: dark; }

body {
    font-family: 'Inter', -apple-system, Segoe UI, Roboto, Arial, sans-serif;
    margin: 0;
    background: var(--bg);
    color: var(--text);
    transition: background .15s ease, color .15s ease;
}

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

.container { max-width: 1100px; margin: 28px auto; padding: 0 20px; }

/* ---------- App shell: sidebar + topbar ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
    width: 230px; flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--border);
    display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar-brand { font-weight: 800; font-size: 17px; letter-spacing: -0.02em; padding: 20px 18px 14px; }
.side-menu { display: flex; flex-direction: column; padding: 6px 12px; gap: 2px; }
.side-menu a {
    color: var(--text-muted); text-decoration: none; font-size: 14px; font-weight: 600;
    padding: 9px 12px; border-radius: 8px; transition: background .12s, color .12s;
}
.side-menu a:hover { background: var(--surface-alt); color: var(--text); }
.side-menu-divider { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); margin: 14px 12px 4px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
    display: flex; align-items: center; gap: 4px; padding: 0 20px; height: 58px;
    background: var(--surface); border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 20; box-shadow: var(--shadow);
}
.topbar .spacer { flex: 1; }
.topbar a { color: var(--text-muted); text-decoration: none; font-size: 14px; font-weight: 600; padding: 8px 10px; border-radius: 8px; }
.topbar a:hover { background: var(--surface-alt); color: var(--text); }
.topbar .bell { position: relative; font-size: 17px; }
.topbar .muted { color: var(--text-muted); }
.theme-toggle {
    background: var(--surface-alt); border: 1px solid var(--border); border-radius: 8px;
    width: 36px; height: 36px; cursor: pointer; font-size: 16px; display: flex;
    align-items: center; justify-content: center; margin-left: 4px;
}

@media (max-width: 780px) {
    .app-shell { flex-direction: column; }
    .sidebar { width: 100%; height: auto; position: static; flex-direction: row; overflow-x: auto; }
    .side-menu { flex-direction: row; }
    .sidebar-brand { padding: 14px 16px; }
}

/* ---------- Auth pages ---------- */
.auth-wrap {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: linear-gradient(160deg, var(--bg), var(--surface-alt));
    position: relative;
}
.auth-box {
    width: 380px; margin: 0 auto; background: var(--surface); padding: 36px 32px;
    border-radius: var(--radius); box-shadow: var(--shadow-md); border: 1px solid var(--border);
}
.auth-box h1 { font-size: 21px; margin: 0 0 22px; letter-spacing: -0.02em; }
.auth-wrap .theme-toggle { position: absolute; top: 20px; right: 20px; }

/* ---------- Forms ---------- */
label { display: block; margin: 14px 0 5px; font-weight: 600; font-size: 13px; color: var(--text); }
input[type=text], input[type=password], input[type=number], input[type=email],
input[type=file], input[type=date], select, textarea {
    width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px;
    font-size: 14px; background: var(--surface); color: var(--text); font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
.card-form { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); }

button, .button {
    display: inline-block; margin-top: 16px; padding: 10px 18px; background: var(--primary); color: #fff;
    border: none; border-radius: 8px; cursor: pointer; font-size: 14px; font-weight: 600; text-decoration: none;
    transition: background .12s;
}
button:hover, .button:hover { background: var(--primary-hover); }
button.danger { background: var(--error); }
button.danger:hover { background: #b91c1c; }

.error { color: var(--error); font-weight: 600; background: var(--error-bg); padding: 10px 14px; border-radius: 8px; }
.success { color: var(--success); font-weight: 600; background: var(--success-bg); padding: 10px 14px; border-radius: 8px; }
.muted { color: var(--text-muted); font-size: 13px; }

/* ---------- Page header / stat cards ---------- */
.page-header { display: flex; align-items: center; justify-content: space-between; margin: 8px 0 18px; }
.page-header h2 { margin: 0; letter-spacing: -0.02em; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin: 18px 0 26px; }
.stat-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 18px; box-shadow: var(--shadow);
}
.stat-card .stat-num { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; }
.stat-card .stat-label { color: var(--text-muted); font-size: 13px; margin-top: 2px; }
.stat-card.accent .stat-num { color: var(--primary); }
.stat-card.warn .stat-num { color: #d97706; }

/* ---------- Tables ---------- */
table.list { width: 100%; border-collapse: collapse; margin: 12px 0 24px; background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
table.list th, table.list td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 14px; }
table.list th { background: var(--surface-alt); font-weight: 700; color: var(--text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
table.list tr:last-child td { border-bottom: none; }

/* ---------- Misc components ---------- */
.checklist { background: var(--surface); padding: 10px; border: 1px solid var(--border); border-radius: 8px; max-height: 260px; overflow-y: auto; }
.checkline { display: flex; align-items: center; gap: 8px; font-weight: 400; margin: 6px 0; }
.doc-body { background: var(--surface); padding: 18px 22px; border-radius: var(--radius); margin: 14px 0; border: 1px solid var(--border); }
.doc-body img { max-width: 100%; }
.doc-body table { border-collapse: collapse; width: 100%; }
.doc-body table td, .doc-body table th { border: 1px solid var(--border); padding: 6px 8px; }

.action-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin: 20px 0; box-shadow: var(--shadow); }
.typed-sig { font-style: italic; font-size: 18px; }
.notice { background: var(--warning-bg); border: 1px solid var(--warning-border); border-radius: 8px; padding: 12px 16px; margin: 16px 0; }
.notice-error { background: var(--error-bg); border-color: var(--error); }
details summary { cursor: pointer; font-weight: 600; margin: 6px 0; }
details form { margin-top: 8px; }

.badge {
    background: var(--badge); color: #fff; font-size: 11px; font-weight: 700;
    border-radius: 10px; padding: 1px 6px; margin-left: 4px;
}
.unread-row { background: var(--surface-alt); font-weight: 600; }
.filter-bar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 12px 0; background: var(--surface); padding: 12px; border-radius: var(--radius); border: 1px solid var(--border); box-shadow: var(--shadow); }
.filter-bar select, .filter-bar input { width: auto; margin: 0; }
.comment { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; margin-bottom: 8px; }
.comment p { margin: 4px 0 0; }

/* ---------- Approver picker (create document) ---------- */
.approver-picker { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 8px; }
.approver-col-title { font-weight: 700; font-size: 12px; text-transform: uppercase; color: var(--text-muted); margin-bottom: 6px; letter-spacing: .03em; }
.approver-list {
    list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--border);
    border-radius: 8px; min-height: 120px; max-height: 320px; overflow-y: auto;
}
.approver-list li {
    display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--border);
    font-size: 14px;
}
.approver-list li:last-child { border-bottom: none; }
.approver-list li .label, .approver-list li > span:first-of-type { flex: 1; }
.approver-list .order-num { font-weight: 700; color: var(--primary); width: 22px; }
.approver-list .move-btns { display: flex; gap: 2px; }
.approver-list button {
    margin: 0; padding: 3px 8px; font-size: 13px; background: var(--surface-alt); color: var(--text);
    border: 1px solid var(--border);
}
.approver-list button:hover { background: var(--border); }
.approver-list .add-btn { background: var(--primary); color: #fff; border: none; }

@media (max-width: 640px) {
    .approver-picker { grid-template-columns: 1fr; }
    .nav { flex-wrap: wrap; height: auto; padding: 10px 14px; }
}

/* ---------- In-browser file reader ---------- */
.file-reader { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; margin: 8px 0; }
.file-reader iframe { width: 100%; height: 640px; border: none; display: block; }
.file-reader img { max-width: 100%; display: block; margin: 0 auto; }
code { background: var(--surface-alt); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
