/* Document Signer — single stylesheet, no build step. */

:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --surface-2: #f0f2f5;
    --border: #e1e4ea;
    --text: #1b1f27;
    --muted: #626b7a;
    --accent: #1f5fd1;
    --accent-hover: #184fb0;
    --accent-soft: #e6eefc;
    --success: #1a7f4b;
    --success-soft: #e3f4ea;
    --warning: #9a6200;
    --warning-soft: #fdf1dc;
    --danger: #c42b2b;
    --danger-soft: #fde8e8;
    --info: #1f5fd1;
    --info-soft: #e6eefc;
    --neutral-soft: #eceef2;
    --sidebar: #141a26;
    --sidebar-text: #b7bfcc;
    --sidebar-active: #ffffff;
    --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
    --radius: 10px;
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0f131a;
        --surface: #171c25;
        --surface-2: #1e2430;
        --border: #2a3140;
        --text: #e6e9ef;
        --muted: #9aa3b2;
        --accent: #5b8ff0;
        --accent-hover: #7aa5f5;
        --accent-soft: #1c2a45;
        --success: #4cc38a;
        --success-soft: #16301f;
        --warning: #e3a13a;
        --warning-soft: #33280f;
        --danger: #f07070;
        --danger-soft: #3a1a1c;
        --info: #5b8ff0;
        --info-soft: #1c2a45;
        --neutral-soft: #262d3a;
        --sidebar: #0b0e14;
        --shadow: 0 1px 2px rgba(0, 0, 0, .4);
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

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

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 650; }
h2 { font-size: 15px; font-weight: 600; }
p { margin: 0 0 8px; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.hidden { display: none !important; }

/* ---------- shell ---------- */

.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }

.sidebar {
    background: var(--sidebar);
    color: var(--sidebar-text);
    padding: 20px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    position: sticky;
    top: 0;
    height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 10px 18px; color: #fff; font-weight: 650; font-size: 15px; }
.brand svg { flex: none; }
.brand small { display: block; font-weight: 400; font-size: 11.5px; color: var(--sidebar-text); }
.nav-link {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 10px; border-radius: 7px;
    color: var(--sidebar-text); font-weight: 500;
}
.nav-link:hover { background: rgba(255, 255, 255, .06); color: #fff; text-decoration: none; }
.nav-link.active { background: rgba(255, 255, 255, .1); color: var(--sidebar-active); }
.nav-link svg { width: 17px; height: 17px; flex: none; opacity: .85; }
.nav-link .count { margin-left: auto; background: var(--danger); color: #fff; font-size: 11px; font-weight: 600; border-radius: 99px; padding: 0 7px; }
.nav-spacer { flex: 1; }
.nav-user { padding: 10px; font-size: 12.5px; border-top: 1px solid rgba(255, 255, 255, .08); margin-top: 8px; }
.nav-user strong { color: #fff; display: block; font-weight: 550; }
.nav-user button { background: none; border: 0; padding: 0; color: var(--sidebar-text); cursor: pointer; font: inherit; text-decoration: underline; }

.main { padding: 28px 32px 48px; min-width: 0; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- surfaces ---------- */

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card + .card, .card + .grid, .grid + .card, .grid + .grid { margin-top: 16px; }
.grid > .card { margin-top: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.card-body { padding: 18px; }
.card-body.flush { padding: 0; }
.empty { padding: 28px 18px; text-align: center; color: var(--muted); }

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

.stat { padding: 16px 18px; }
.stat .label { color: var(--muted); font-size: 12.5px; font-weight: 500; }
.stat .value { font-size: 26px; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat.danger .value { color: var(--danger); }

/* ---------- tables ---------- */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.error-text { color: var(--danger); font-size: 12.5px; word-break: break-word; }

/* ---------- badges, progress ---------- */

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 550; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.success { background: var(--success-soft); color: var(--success); }
.badge.warning { background: var(--warning-soft); color: var(--warning); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.info::before { animation: pulse 1.2s ease-in-out infinite; }
.badge.neutral { background: var(--neutral-soft); color: var(--muted); }
@keyframes pulse { 50% { opacity: .25; } }

.progress { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; display: flex; }
.progress span { display: block; height: 100%; transition: width .4s ease; }
.progress .ok { background: var(--success); }
.progress .bad { background: var(--danger); }
.progress .skip { background: var(--muted); opacity: .5; }
.progress.lg { height: 12px; }

.chips { display: flex; gap: 18px; flex-wrap: wrap; margin-top: 12px; font-size: 13px; }
.chips strong { font-variant-numeric: tabular-nums; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.dot.ok { background: var(--success); } .dot.bad { background: var(--danger); } .dot.run { background: var(--info); } .dot.wait { background: var(--border); }

/* ---------- forms ---------- */

label { display: block; font-weight: 550; margin-bottom: 5px; }
.field { margin-bottom: 16px; }
.field .hint { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.field .error { color: var(--danger); font-size: 12.5px; margin-top: 4px; }
input[type=text], input[type=email], input[type=password], input[type=number], select, textarea {
    width: 100%; padding: 8px 10px; font: inherit; color: var(--text);
    background: var(--surface); border: 1px solid var(--border); border-radius: 7px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { resize: vertical; min-height: 70px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.check input { width: 16px; height: 16px; margin: 0; }
.row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.input-group { display: flex; }
.input-group input { border-radius: 7px 0 0 7px; }
.input-group .btn { border-radius: 0 7px 7px 0; border-left: 0; }

.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 650; margin: 0 0 12px; }

.options { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
.option { position: relative; display: block; margin: 0; padding: 12px 14px; border: 1px solid var(--border); border-radius: 9px; cursor: pointer; font-weight: 400; background: var(--surface); }
.option:hover { border-color: var(--accent); }
.option input { position: absolute; opacity: 0; pointer-events: none; }
.option:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); background: var(--accent-soft); }
.option strong { display: block; font-weight: 600; }
.option .muted { font-size: 12.5px; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 7px 14px; font: inherit; font-weight: 550; line-height: 1.4;
    border: 1px solid var(--border); border-radius: 7px; background: var(--surface); color: var(--text);
    cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.sm { padding: 3px 9px; font-size: 12.5px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg { width: 15px; height: 15px; }
form.inline { display: inline; }

/* ---------- alerts, toasts ---------- */

.alert { padding: 11px 14px; border-radius: 8px; margin-bottom: 16px; border: 1px solid transparent; }
.alert.success { background: var(--success-soft); color: var(--success); }
.alert.error { background: var(--danger-soft); color: var(--danger); }
.alert.warning { background: var(--warning-soft); color: var(--warning); }
.alert ul { margin: 4px 0 0; padding-left: 18px; }

.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 50; max-width: min(380px, calc(100vw - 32px)); }
.toast {
    background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--danger);
    border-radius: 8px; box-shadow: 0 8px 24px rgba(0, 0, 0, .18); padding: 12px 14px;
    animation: slide-in .25s ease;
}
.toast strong { display: block; color: var(--danger); margin-bottom: 2px; }
.toast .msg { font-size: 12.5px; word-break: break-word; }
.toast .close { float: right; background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 16px; line-height: 1; }
@keyframes slide-in { from { transform: translateY(12px); opacity: 0; } }

/* ---------- log ---------- */

.log { font-family: var(--mono); font-size: 12px; max-height: 420px; overflow-y: auto; padding: 10px 0; background: var(--surface-2); border-radius: 0 0 var(--radius) var(--radius); }
.log div { padding: 2px 16px; white-space: pre-wrap; word-break: break-word; }
.log .t { color: var(--muted); margin-right: 8px; }
.log .f { color: var(--accent); margin-right: 6px; }
.log .error { color: var(--danger); }
.log .success { color: var(--success); }
.log .warning { color: var(--warning); }

.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 10px 18px; border-bottom: 1px solid var(--border); display: flex; gap: 10px; justify-content: space-between; align-items: flex-start; }
.list li:last-child { border-bottom: 0; }
.list .grow { min-width: 0; flex: 1; }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs a { padding: 4px 10px; border-radius: 6px; color: var(--muted); font-weight: 500; font-size: 13px; }
.tabs a:hover { background: var(--surface-2); text-decoration: none; }
.tabs a.active { background: var(--accent-soft); color: var(--accent); }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }

.picker { border: 1px solid var(--border); border-radius: 8px; margin-top: 8px; background: var(--surface-2); }
.picker-head { padding: 8px 12px; border-bottom: 1px solid var(--border); font-size: 12.5px; display: flex; justify-content: space-between; gap: 8px; }
.picker-list { max-height: 200px; overflow-y: auto; }
.picker-list button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 6px 12px; font: inherit; color: var(--text); cursor: pointer; }
.picker-list button:hover { background: var(--accent-soft); }
.picker-list .folder::before { content: ""; display: inline-block; width: 13px; height: 10px; margin-right: 8px; border: 1.5px solid var(--muted); border-radius: 2px 2px 3px 3px; border-top-width: 3px; vertical-align: -1px; }

.signer-row { display: grid; grid-template-columns: 28px minmax(200px, 2fr) minmax(130px, 1fr) minmax(110px, 1fr) minmax(170px, 1.2fr) 36px; gap: 8px; align-items: start; padding: 10px 0; border-bottom: 1px dashed var(--border); }
.signer-row .n { font-weight: 650; color: var(--muted); padding-top: 8px; }

.pagination { display: flex; gap: 4px; padding: 12px 16px; flex-wrap: wrap; align-items: center; }
.pagination a, .pagination span { padding: 3px 9px; border-radius: 6px; font-size: 13px; }
.pagination .current { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* ---------- login ---------- */

.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth .card { width: 100%; max-width: 380px; }
.auth .brand { color: var(--text); padding: 0 0 18px; justify-content: center; }
.auth .brand small { color: var(--muted); }

/* ---------- responsive ---------- */

@media (max-width: 1100px) {
    .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid-main { grid-template-columns: 1fr; }
}

@media (max-width: 800px) {
    .shell { grid-template-columns: 1fr; }
    .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; padding: 10px 12px; align-items: center; }
    .brand { padding: 0 8px 0 4px; width: 100%; }
    .nav-spacer { display: none; }
    .nav-user { border: 0; margin: 0; padding: 8px 10px; }
    .main { padding: 20px 16px 40px; }
    .grid-2, .grid-3 { grid-template-columns: 1fr; }
    .signer-row { grid-template-columns: 1fr; }
    .signer-row .n { padding: 0; }
}
