/*
 * knot-dash design system.
 * 4px radii max (pills/avatars excepted). Cool/neutral palette. Inter.
 * Accent deep slate-blue #2c3e63. No hover motion/transform; color only.
 */

:root {
    --accent: #2c3e63;
    --accent-strong: #233252;
    --accent-soft: #eef1f6;
    --success: #2e7d4f;
    --danger: #b3392e;

    --bg: #f4f5f7;
    --surface: #ffffff;
    --border: #e2e5ea;
    --border-strong: #d3d8e0;

    --text: #1b2233;
    --text-muted: #6b7280;
    --text-faint: #9aa1ad;

    --radius: 4px;
    --radius-sm: 3px;
    --sidebar-w: 230px;

    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    --shadow-card: 0 1px 2px rgba(16, 24, 40, 0.04);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
}

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

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-strong); }

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }

/* =========================================================
   Buttons
   ========================================================= */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    padding: 0.5rem 0.9rem;
    font-family: var(--font);
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1;
    border: 1px solid transparent;
    border-radius: var(--radius);
    background: transparent;
    color: var(--text);
    cursor: pointer;
    text-decoration: none;
}
.btn svg { display: block; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; }
.btn-ghost { background: var(--surface); border-color: var(--border-strong); color: var(--text); }
.btn-ghost:hover { background: var(--accent-soft); color: var(--accent-strong); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #97302a; border-color: #97302a; color: #fff; }
.btn-sm { padding: 0.35rem 0.65rem; font-size: 0.8125rem; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* =========================================================
   Cards
   ========================================================= */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    padding: 1.25rem 1.5rem;
    margin-bottom: 1.25rem;
}
.card-narrow { max-width: 560px; }
.card-title { font-size: 1rem; font-weight: 600; margin: 0 0 0.5rem; }
.card-text { color: var(--text-muted); margin: 0; }

/* =========================================================
   Forms
   ========================================================= */
.form-group { margin-bottom: 1.1rem; }
.form-row { display: flex; gap: 1rem; }
.form-row .form-group { flex: 1; }
.form-label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 0.4rem;
}
.form-optional { color: var(--text-faint); font-weight: 400; }
.form-control {
    width: 100%;
    padding: 0.55rem 0.7rem;
    font-family: var(--font);
    font-size: 0.9375rem;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
}
.form-control:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(44, 62, 99, 0.12);
}
.form-actions { margin-top: 1.25rem; display: flex; justify-content: flex-end; gap: 0.5rem; }
.form-actions-left { justify-content: flex-start; }

/* =========================================================
   Badges
   ========================================================= */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.15rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent-strong);
}
.badge-success { background: #e6f1ea; color: var(--success); }
.badge-danger { background: #f6e6e4; color: var(--danger); }

/* =========================================================
   Alerts
   ========================================================= */
.alert {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    padding: 0.75rem 0.9rem;
    border: 1px solid;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.875rem;
}
.alert svg { flex-shrink: 0; margin-top: 1px; }
.alert-success { background: #eef6f1; border-color: #cfe6d8; color: #205c3b; }
.alert-danger { background: #f9ecea; border-color: #ecccc8; color: #8e2c24; }

/* =========================================================
   Auth pages
   ========================================================= */
.auth-body { background: var(--bg); }
.auth-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
}
.auth-card {
    width: 100%;
    max-width: 400px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    padding: 2rem;
}
.auth-card-center { text-align: center; }
.auth-brand {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--accent);
    font-weight: 600;
    font-size: 1.05rem;
    margin-bottom: 1.25rem;
}
.auth-brand-center { display: flex; justify-content: center; }
.auth-title { font-size: 1.4rem; margin-bottom: 0.4rem; }
.auth-subtitle { color: var(--text-muted); margin: 0 0 1.5rem; font-size: 0.875rem; }
.auth-form .form-group:last-of-type { margin-bottom: 1.25rem; }
.auth-note { margin-top: 0.75rem; text-align: center; color: var(--text-faint); font-size: 0.8125rem; }
.auth-steps {
    background: var(--accent-soft);
    border-radius: var(--radius);
    padding: 0.9rem 1rem;
    margin-bottom: 1.25rem;
    text-align: left;
}
.auth-steps-title { font-size: 0.8125rem; font-weight: 600; color: var(--accent-strong); margin: 0 0 0.4rem; }
.auth-steps ol { margin: 0; padding-left: 1.1rem; color: var(--text-muted); font-size: 0.8125rem; }
.auth-steps li { margin-bottom: 0.2rem; }
.auth-actions { margin-top: 1.25rem; display: flex; flex-direction: column; align-items: center; gap: 0.75rem; }
.turnstile-wrap { margin-bottom: 1rem; }
.hp-trap { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

.error-code { font-size: 3rem; font-weight: 700; color: var(--accent); letter-spacing: -0.02em; margin-bottom: 0.25rem; }

.spinner {
    width: 26px;
    height: 26px;
    border: 2px solid var(--border-strong);
    border-top-color: var(--accent);
    border-radius: 999px;
    animation: knot-spin 0.8s linear infinite;
}
@keyframes knot-spin { to { transform: rotate(360deg); } }

/* =========================================================
   Dashboard layout
   ========================================================= */
.dash-body { background: var(--bg); }

.sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 1rem 0.75rem;
}
.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--accent);
    font-weight: 600;
    font-size: 1.05rem;
    padding: 0.4rem 0.5rem 1rem;
    letter-spacing: -0.01em;
}
.sidebar-nav { display: flex; flex-direction: column; gap: 1px; flex: 1; overflow-y: auto; }
.nav-item {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.5rem 0.6rem;
    border-radius: var(--radius);
    color: var(--text-muted);
    font-size: 0.875rem;
    font-weight: 500;
}
.nav-item:hover { background: var(--accent-soft); color: var(--accent-strong); }
.nav-item.is-active { background: var(--accent-soft); color: var(--accent-strong); }
.nav-icon { display: inline-flex; color: inherit; }
.nav-label { line-height: 1; }
.sidebar-foot { border-top: 1px solid var(--border); padding-top: 0.75rem; margin-top: 0.5rem; }
.sidebar-user { padding: 0.25rem 0.6rem 0.5rem; }
.sidebar-user-email {
    display: block;
    font-size: 0.75rem;
    color: var(--text-faint);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.nav-item-foot { color: var(--text-muted); }

.content {
    margin-left: var(--sidebar-w);
    min-height: 100vh;
    padding: 1.5rem 2rem;
}
.content-inner { max-width: 980px; }

.page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.page-title { font-size: 1.5rem; }
.page-sub { color: var(--text-muted); margin: 0.25rem 0 0; font-size: 0.9rem; }
.page-head-actions { display: flex; gap: 0.5rem; flex-shrink: 0; }

/* Stat cards */
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-bottom: 1.25rem; }
.stat-card { display: flex; flex-direction: column; gap: 0.35rem; padding: 1.1rem 1.25rem; margin-bottom: 0; }
.stat-icon { color: var(--accent); }
.stat-value { font-size: 1.75rem; font-weight: 700; line-height: 1; letter-spacing: -0.01em; }
.stat-label { color: var(--text-muted); font-size: 0.8125rem; }

/* Tables */
.table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.table th, .table td { text-align: left; padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--border); }
.table th { color: var(--text-muted); font-weight: 500; font-size: 0.8125rem; }
.table tr:last-child td { border-bottom: none; }

/* =========================================================
   Toast
   ========================================================= */
.toast {
    padding: 0.6rem 0.9rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    margin-bottom: 1rem;
    border: 1px solid;
}
.toast-success { background: #eef6f1; border-color: #cfe6d8; color: #205c3b; }
.toast-error { background: #f9ecea; border-color: #ecccc8; color: #8e2c24; }

#knot-toast-host {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
#knot-toast-host .toast { margin-bottom: 0; box-shadow: var(--shadow-card); background: var(--surface); }

/* =========================================================
   Modal
   ========================================================= */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(20, 26, 40, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 900;
    padding: 1rem;
}
.modal-backdrop[hidden] { display: none !important; }
.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 10px 30px rgba(16, 24, 40, 0.18);
    width: 100%;
    max-width: 480px;
    padding: 1.5rem;
}
.modal-title { font-size: 1.1rem; font-weight: 600; margin-bottom: 0.75rem; }

@media (max-width: 720px) {
    .sidebar { position: static; width: 100%; flex-direction: column; }
    .content { margin-left: 0; padding: 1.25rem; }
    .stat-grid { grid-template-columns: 1fr; }
    .form-row { flex-direction: column; gap: 0; }
}
