/* ===== Legend Sleep SEO Tracker — design tokens ===== */
:root {
    --bg: #f4f6fb;
    --surface: #ffffff;
    --surface-2: #f8f9fd;
    --border: #e4e7f0;
    --text: #1c2333;
    --text-dim: #6b7280;
    --text-faint: #9aa1b1;

    --brand: #4f46e5;
    --brand-dark: #3f37c9;
    --brand-light: #eef0ff;
    --teal: #0d9488;
    --teal-light: #ecfdf9;

    --ok: #16a34a;
    --ok-light: #ecfdf3;
    --warn: #d97706;
    --warn-light: #fffaeb;
    --danger: #dc2626;
    --danger-light: #fef2f2;
    --info: #2563eb;
    --info-light: #eff6ff;
    --muted: #6b7280;
    --muted-light: #f1f2f6;

    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 18px;
    --shadow-sm: 0 1px 2px rgba(20, 24, 40, .06);
    --shadow: 0 4px 16px rgba(20, 24, 40, .08);
    --shadow-lg: 0 12px 32px rgba(20, 24, 40, .14);
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; font-weight: 700; }
p { margin: 0; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; }
::-webkit-scrollbar { height: 8px; width: 8px; }
::-webkit-scrollbar-thumb { background: #d3d7e3; border-radius: 8px; }

/* ===== Login ===== */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: radial-gradient(circle at 20% 20%, #6a63f1 0%, #4338ca 45%, #241f6e 100%);
    padding: 20px;
}
.login-card {
    width: 100%;
    max-width: 380px;
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 36px 32px;
}
.login-brand { text-align: center; margin-bottom: 24px; }
.login-logo {
    width: 56px; height: 56px; margin: 0 auto 14px;
    border-radius: 16px;
    background: linear-gradient(135deg, var(--brand), var(--teal));
    color: #fff; font-weight: 800; font-size: 20px;
    display: flex; align-items: center; justify-content: center;
    box-shadow: var(--shadow);
}
.login-brand h1 { font-size: 20px; }
.login-brand p { color: var(--text-dim); font-size: 13px; margin-top: 4px; }
.login-form { display: flex; flex-direction: column; gap: 14px; margin-top: 8px; }
.login-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--text-dim); }
.login-form input {
    padding: 11px 13px; border-radius: var(--radius-sm); border: 1px solid var(--border);
    background: var(--surface-2); font-size: 14px; color: var(--text);
}
.login-form input:focus { outline: none; border-color: var(--brand); background: #fff; box-shadow: 0 0 0 3px var(--brand-light); }

/* ===== Buttons ===== */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 9px 16px; border-radius: var(--radius-sm); border: 1px solid transparent;
    font-size: 13.5px; font-weight: 600; transition: all .15s ease; white-space: nowrap;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-block { width: 100%; padding: 11px; }
.btn-ghost { background: transparent; color: var(--text-dim); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-outline { background: #fff; color: var(--brand); border-color: var(--brand-light); }
.btn-outline:hover { background: var(--brand-light); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; border-radius: 7px; }
.btn-icon { padding: 6px 8px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ===== App shell ===== */
.app { min-height: 100vh; display: flex; flex-direction: column; }

.app-header { position: sticky; top: 0; z-index: 30; background: var(--surface); }

.topbar {
    display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px;
    padding: 12px 20px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar-brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
    width: 38px; height: 38px; border-radius: 11px; flex-shrink: 0;
    background: linear-gradient(135deg, var(--brand), var(--teal));
    color: #fff; font-weight: 800; font-size: 14px;
    display: flex; align-items: center; justify-content: center;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 14.5px; }
.brand-text span { font-size: 11.5px; color: var(--text-dim); }
.topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }

.chip {
    display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
    padding: 6px 12px; border-radius: 100px; font-size: 12.5px; font-weight: 700;
    background: var(--muted-light); color: var(--text-dim);
}
.chip-phase { background: var(--brand-light); color: var(--brand-dark); }
.chip-overdue { background: var(--danger-light); color: var(--danger); animation: pulse-red 1.8s infinite; }
.siren { display: inline-block; }
@keyframes pulse-red {
    0%, 100% { box-shadow: 0 0 0 0 rgba(220,38,38,.25); }
    50% { box-shadow: 0 0 0 6px rgba(220,38,38,0); }
}

.tabbar {
    display: flex; gap: 4px; padding: 0 16px; background: var(--surface);
    border-bottom: 1px solid var(--border); overflow-x: auto;
    scrollbar-width: none;
}
.tabbar::-webkit-scrollbar { display: none; }
.tab-btn {
    flex-shrink: 0; padding: 12px 16px; background: none; border: none; border-bottom: 3px solid transparent;
    font-size: 13.5px; font-weight: 600; color: var(--text-dim);
}
.tab-btn.active { color: var(--brand); border-bottom-color: var(--brand); }
.tab-btn:hover:not(.active) { color: var(--text); }

.content { flex: 1; padding: 18px; max-width: 1320px; width: 100%; margin: 0 auto; }
.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fade-in .2s ease; }
@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ===== Dashboard cards ===== */
.grid-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 18px; }
.card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 16px; box-shadow: var(--shadow-sm);
}
.stat-card .stat-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--text-faint); }
.stat-card .stat-value { font-size: 28px; font-weight: 800; margin-top: 6px; }
.stat-card .stat-sub { font-size: 12px; color: var(--text-dim); margin-top: 4px; }
.stat-card.accent-danger .stat-value { color: var(--danger); }
.stat-card.accent-ok .stat-value { color: var(--ok); }
.stat-card.accent-brand .stat-value { color: var(--brand); }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); margin-bottom: 18px; overflow: hidden; }
.panel-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); flex-wrap: wrap; gap: 8px; }
.panel-header h3 { font-size: 15px; }
.panel-header p { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.panel-body { padding: 18px; }

.progress-track { height: 9px; border-radius: 100px; background: var(--muted-light); overflow: hidden; }
.progress-fill { height: 100%; border-radius: 100px; background: linear-gradient(90deg, var(--brand), var(--teal)); transition: width .4s ease; }

.week-bars { display: flex; align-items: flex-end; gap: 6px; height: 90px; }
.week-bar-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.week-bar-col { width: 100%; height: 64px; background: var(--muted-light); border-radius: 6px 6px 2px 2px; display: flex; align-items: flex-end; overflow: hidden; }
.week-bar-fill { width: 100%; background: linear-gradient(180deg, var(--teal), var(--brand)); border-radius: 6px 6px 0 0; }
.week-bar-label { font-size: 10px; color: var(--text-faint); font-weight: 700; }

.kpi-mini-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; }
.kpi-mini { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; background: var(--surface-2); }
.kpi-mini .kpi-name { font-size: 12.5px; font-weight: 700; color: var(--text); margin-bottom: 6px; }
.kpi-mini .kpi-nums { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--text-dim); margin-top: 6px; }

.compare-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.compare-table th, .compare-table td { padding: 9px 10px; border-bottom: 1px solid var(--border); text-align: left; }
.compare-table th { color: var(--text-dim); font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em; }
.compare-table td.us { font-weight: 700; color: var(--brand-dark); }
.compare-table tr:last-child td { border-bottom: none; }

.live-score-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border); }
.live-score-row:last-child { border-bottom: none; }
.live-score-domain { font-weight: 700; font-size: 13px; }
.live-score-domain small { display: block; font-weight: 400; color: var(--text-faint); font-size: 11px; }
.live-score-value { font-size: 20px; font-weight: 800; color: var(--teal); }
.notice { padding: 12px 14px; border-radius: var(--radius-sm); font-size: 12.5px; line-height: 1.5; }
.notice-info { background: var(--info-light); color: #1d4ed8; }
.notice a { text-decoration: underline; }

/* ===== Toolbar / filters ===== */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.toolbar .spacer { flex: 1; }
.input, .select {
    padding: 8px 11px; border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--surface); font-size: 13px; color: var(--text);
}
.input:focus, .select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-light); }
.input-search { min-width: 200px; flex: 1; max-width: 320px; }

/* ===== Week accordion (Daily Tasks) ===== */
.week-group { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 12px; overflow: hidden; }
.week-group-header {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 13px 16px; cursor: pointer; background: var(--surface-2); flex-wrap: wrap;
}
.week-group-title { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 13.5px; }
.week-group-title .phase-tag { font-size: 10.5px; font-weight: 700; padding: 3px 8px; border-radius: 100px; background: var(--brand-light); color: var(--brand-dark); }
.week-group-meta { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--text-dim); }
.week-progress-mini { width: 90px; }
.week-group-body { display: none; }
.week-group.open .week-group-body { display: block; }
.week-group-chevron { transition: transform .15s ease; color: var(--text-faint); }
.week-group.open .week-group-chevron { transform: rotate(90deg); }

/* ===== Task/row cards ===== */
.row-list { display: flex; flex-direction: column; }
.row-item {
    display: grid; grid-template-columns: 26px 1fr auto; gap: 12px; align-items: start;
    padding: 12px 16px; border-top: 1px solid var(--border);
}
.row-item:first-child { border-top: none; }
.row-item.overdue { background: var(--danger-light); }
.row-check { width: 20px; height: 20px; margin-top: 2px; }
.row-main { min-width: 0; }
.row-title-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row-title { font-weight: 700; font-size: 13.5px; }
.row-badges { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.tag { font-size: 10.5px; font-weight: 700; padding: 2px 8px; border-radius: 100px; background: var(--muted-light); color: var(--text-dim); white-space: nowrap; }
.tag-track { background: var(--brand-light); color: var(--brand-dark); }
.tag-owner { background: var(--teal-light); color: var(--teal); }
.tag-date { background: var(--surface-2); color: var(--text-faint); border: 1px solid var(--border); }
.tag-overdue { background: var(--danger); color: #fff; }
.row-why { font-size: 12px; color: var(--text-dim); margin-top: 5px; }
.row-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; flex-wrap: wrap; justify-content: flex-end; }

.status-select {
    font-size: 11.5px; font-weight: 700; padding: 5px 8px; border-radius: 100px; border: 1px solid var(--border);
    background: var(--surface-2); color: var(--text); appearance: none; cursor: pointer; text-align: center;
}
.status-select[data-status="Not started"] { background: var(--muted-light); color: var(--text-dim); }
.status-select[data-status="In progress"] { background: var(--info-light); color: var(--info); }
.status-select[data-status="Completed"] { background: var(--ok-light); color: var(--ok); }
.status-select[data-status="Cancelled"] { background: var(--danger-light); color: var(--danger); }
.status-select[data-status="Updated"] { background: var(--warn-light); color: var(--warn); }

.assignee-select { font-size: 11.5px; font-weight: 600; padding: 5px 8px; border-radius: 7px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }

/* ===== Simple table view (used for backlinks/audit/url map) ===== */
.data-table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 12.8px; min-width: 720px; }
.data-table th { text-align: left; padding: 9px 10px; background: var(--surface-2); color: var(--text-dim); font-size: 11px; text-transform: uppercase; letter-spacing: .03em; border-bottom: 1px solid var(--border); white-space: nowrap; }
.data-table td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.data-table tr.overdue td { background: var(--danger-light); }
.data-table tr:hover td { background: var(--surface-2); }
.data-table tr.overdue:hover td { background: #fde4e4; }
.cell-actions { display: flex; gap: 4px; white-space: nowrap; }
.link-cell { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty-state { text-align: center; padding: 40px 20px; color: var(--text-faint); font-size: 13px; }

/* ===== Modal ===== */
.modal-root { position: fixed; inset: 0; z-index: 100; display: flex; align-items: flex-end; justify-content: center; }
.modal-root.hidden { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(20, 24, 40, .5); backdrop-filter: blur(2px); }
.modal-box {
    position: relative; background: var(--surface); width: 100%; max-width: 560px; max-height: 92vh;
    border-radius: 18px 18px 0 0; box-shadow: var(--shadow-lg); overflow-y: auto; animation: slide-up .18s ease;
    padding: 20px;
}
@keyframes slide-up { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (min-width: 640px) {
    .modal-root { align-items: center; }
    .modal-box { border-radius: 18px; margin: 20px; }
}
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-header h3 { font-size: 16px; }
.modal-close { background: none; border: none; font-size: 20px; color: var(--text-faint); padding: 4px 8px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12px; font-weight: 700; color: var(--text-dim); }
.field input, .field select, .field textarea {
    padding: 9px 11px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
}
.field textarea { resize: vertical; min-height: 60px; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--brand); background: #fff; box-shadow: 0 0 0 3px var(--brand-light); }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.pin-box { display: flex; flex-direction: column; gap: 10px; align-items: center; text-align: center; padding: 10px 0; }
.pin-input { width: 140px; text-align: center; letter-spacing: 8px; font-size: 20px; padding: 10px; border-radius: var(--radius-sm); border: 1px solid var(--border); }
@media (max-width: 560px) { .form-grid { grid-template-columns: 1fr; } }

/* ===== Toast ===== */
.toast-root { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { padding: 10px 18px; border-radius: 100px; font-size: 13px; font-weight: 600; box-shadow: var(--shadow-lg); color: #fff; background: var(--text); animation: toast-in .2s ease; }
.toast-ok { background: var(--ok); }
.toast-err { background: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.hidden { display: none !important; }

/* ===== Mobile ===== */
@media (max-width: 720px) {
    .topbar { padding: 10px 14px; }
    .brand-text span { display: none; }
    .content { padding: 12px; }
    .row-item { grid-template-columns: 22px 1fr; }
    .row-actions { grid-column: 1 / -1; justify-content: flex-start; margin-top: 6px; }
    .panel-body { padding: 14px; }
    .grid-cards { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 420px) {
    .grid-cards { grid-template-columns: 1fr 1fr; }
    .stat-card .stat-value { font-size: 22px; }
}
