/** Phase 6 — Responsive, lightweight dashboard visual system and chart/table layouts. */
:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #182733;
  background: #f4f7f8;
  --navy: #102a3b;
  --navy-soft: #18394d;
  --teal: #138a7e;
  --teal-dark: #0c6c63;
  --blue: #3973e6;
  --amber: #e8a23a;
  --violet: #805ad5;
  --border: #dfe7ea;
  --muted: #6d7d88;
  --surface: #fff;
  --danger: #b42318;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; min-height: 100vh; background: #f4f7f8; }
body.is-loading .main-content { cursor: progress; }
body.is-loading .main-content::after { content: ""; position: fixed; inset: 0 0 auto; z-index: 20; height: 3px; background: linear-gradient(90deg, transparent, var(--teal), transparent); }
button, input, select { font: inherit; }
button { border: 0; border-radius: .68rem; padding: .72rem 1rem; color: white; background: var(--teal); font-weight: 750; cursor: pointer; }
button:hover { background: var(--teal-dark); }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible { outline: 3px solid rgba(19,138,126,.25); outline-offset: 2px; }
button:disabled { cursor: not-allowed; opacity: .5; }
input, select { width: 100%; border: 1px solid var(--border); border-radius: .62rem; padding: .72rem .82rem; color: inherit; background: white; }
input:focus, select:focus { border-color: var(--teal); outline: 3px solid rgba(19,138,126,.12); }
label { display: block; margin: 1rem 0 .4rem; font-size: .88rem; font-weight: 750; }
h1, h2, p { margin-top: 0; }
h1 { letter-spacing: -.035em; }
h2 { margin-bottom: 0; font-size: 1.05rem; letter-spacing: -.015em; }
a { color: var(--teal); }
[hidden] { display: none !important; }
.centered { text-align: center; }
.muted { color: var(--muted); }
.eyebrow { margin-bottom: .38rem; color: var(--teal); text-transform: uppercase; letter-spacing: .13em; font-size: .68rem; font-weight: 850; }
.brand-mark { display: grid; place-items: center; width: 3.55rem; height: 3.55rem; margin: 0 auto 1rem; border: 1px solid rgba(255,255,255,.18); border-radius: 1.05rem; color: #fff; background: linear-gradient(145deg, #0f766e, #62b9ac); box-shadow: 0 10px 25px rgba(19,138,126,.2); font-weight: 900; }
.brand-mark.small { width: 2.6rem; height: 2.6rem; margin: 0; border-radius: .78rem; box-shadow: none; font-size: .8rem; }
.centered-view { min-height: 100vh; display: grid; place-content: center; padding: 1.25rem; text-align: center; }
.login-background { background: radial-gradient(circle at 20% 10%, rgba(74,180,166,.16), transparent 35%), radial-gradient(circle at 90% 90%, rgba(57,115,230,.1), transparent 35%), #f4f7f8; }
.auth-card { width: min(26rem, calc(100vw - 2rem)); padding: 2.35rem; border: 1px solid var(--border); border-radius: 1.3rem; background: var(--surface); box-shadow: 0 24px 70px rgba(16,42,59,.12); text-align: left; }
.auth-card h1 { margin-bottom: .55rem; text-align: center; }
.auth-card button { width: 100%; margin-top: 1rem; }
.challenge { min-height: 65px; margin-top: 1.1rem; }
.form-error { margin: .75rem 0 0; color: var(--danger); font-size: .86rem; }

.app-shell { display: grid; grid-template-columns: 15.6rem minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; z-index: 10; height: 100vh; display: flex; flex-direction: column; padding: 1.35rem 1rem; color: #fff; background: var(--navy); }
.brand { display: flex; align-items: center; gap: .75rem; margin: .2rem .45rem 2.1rem; color: white; text-decoration: none; font-weight: 850; line-height: 1.05; }
.sidebar nav { display: grid; gap: .36rem; }
.sidebar nav a { display: flex; align-items: center; gap: .7rem; padding: .78rem .88rem; border-radius: .65rem; color: #b9ccd7; text-decoration: none; font-weight: 680; }
.sidebar nav a span { width: 1.25rem; color: #75bdb5; text-align: center; }
.sidebar nav a:hover, .sidebar nav a.active { color: #fff; background: var(--navy-soft); }
.sidebar-foot { display: flex; align-items: center; gap: .5rem; margin: auto .6rem 1rem; color: #a9bec9; font-size: .75rem; }
.health-dot { width: .5rem; height: .5rem; border-radius: 50%; background: #44d19d; box-shadow: 0 0 0 4px rgba(68,209,157,.12); }
.sidebar-logout { width: 100%; color: #d5e1e7; background: transparent; border: 1px solid rgba(255,255,255,.16); }
.sidebar-logout:hover { color: white; background: rgba(255,255,255,.07); }

.main-content { width: 100%; max-width: 105rem; padding: 2rem clamp(1rem, 3vw, 3rem) 4rem; overflow: hidden; }
.page-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.35rem; }
.page-header h1 { margin-bottom: 0; font-size: clamp(1.55rem, 3vw, 2.1rem); }
.header-actions { display: flex; gap: .65rem; }
.compact { padding: .58rem .78rem; }
.secondary { color: #344a58; background: white; border: 1px solid var(--border); }
.secondary:hover { background: #f5f8f9; }
.notice { padding: .78rem 1rem; border: 1px solid #abefc6; border-radius: .72rem; color: #067647; background: #ecfdf3; }
.notice[data-kind="error"] { border-color: #fecdca; color: var(--danger); background: #fef3f2; }
.analytics-toolbar { display: flex; align-items: flex-end; gap: .85rem; margin-bottom: 1.15rem; padding: .75rem; border: 1px solid var(--border); border-radius: .85rem; background: rgba(255,255,255,.76); }
.field-inline { min-width: 13rem; margin: 0; }
.field-inline span, .custom-range label span { display: block; margin-bottom: .3rem; color: var(--muted); font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; }
.range-group { display: flex; gap: .35rem; margin-left: auto; }
.range-button { padding: .62rem .8rem; font-size: .82rem; }
.range-button.active { border-color: var(--teal); color: white; background: var(--teal); }
.custom-range { display: flex; align-items: flex-end; gap: .45rem; }
.custom-range label { margin: 0; }
.custom-range input { padding: .55rem .6rem; }

.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.kpi-card { display: flex; align-items: flex-start; gap: .9rem; min-width: 0; padding: 1.15rem; border: 1px solid var(--border); border-radius: .95rem; background: var(--surface); box-shadow: 0 5px 20px rgba(16,42,59,.035); }
.kpi-icon { flex: 0 0 auto; display: grid; place-items: center; width: 2.35rem; height: 2.35rem; border-radius: .72rem; font-weight: 850; }
.kpi-icon.teal { color: #087b70; background: #e5f7f4; }
.kpi-icon.blue { color: #2e64cf; background: #eaf0fd; }
.kpi-icon.amber { color: #b66c04; background: #fff4df; }
.kpi-icon.violet { color: #6842b9; background: #f1ebfb; }
.kpi-card p { margin-bottom: .35rem; color: var(--muted); font-size: .8rem; }
.kpi-card strong { display: block; margin-bottom: .3rem; font-size: clamp(1.35rem, 2.6vw, 1.85rem); letter-spacing: -.04em; white-space: nowrap; }
.kpi-card small { font-size: .7rem; white-space: nowrap; }
.positive { color: #067647; }
.negative { color: var(--danger); }

.panel { overflow: hidden; border: 1px solid var(--border); border-radius: .95rem; background: var(--surface); box-shadow: 0 5px 22px rgba(16,42,59,.035); }
.chart-panel, .table-panel, .setting-card { margin-bottom: 1rem; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1.05rem 1.15rem .5rem; }
.panel-heading a { font-size: .78rem; font-weight: 750; text-decoration: none; }
.panel-meta { color: var(--muted); font-size: .75rem; }
.chart-height-main { height: 20rem; padding: .4rem 1rem 1rem; }
.chart-height-hours { height: 15rem; padding: .4rem 1rem 1rem; }
.chart-height-donut { width: 10.5rem; height: 10.5rem; }
.insight-grid { display: grid; grid-template-columns: 1.15fr .85fr; gap: 1rem; margin-bottom: 1rem; }
.insight-card { min-height: 16rem; }
.donut-layout { display: flex; align-items: center; justify-content: center; gap: 1.5rem; padding: .7rem 1.1rem 1.2rem; }
.legend-list { min-width: 8.5rem; display: grid; gap: .7rem; }
.legend-list > div { display: flex; justify-content: space-between; gap: 1rem; font-size: .8rem; }
.legend-list span { display: flex; align-items: center; gap: .45rem; color: var(--muted); }
.legend-dot { width: .55rem; height: .55rem; border-radius: 50%; }
.color-0 { background: var(--teal); }.color-1 { background: var(--blue); }.color-2 { background: var(--amber); }.color-3 { background: #a7b1b8; }
.rank-list { display: grid; gap: .8rem; padding: .7rem 1.15rem 1.2rem; }
.rank-item { display: grid; grid-template-columns: 1.5rem minmax(0, 1fr) auto; align-items: center; gap: .7rem; }
.rank-number { color: #98a4ab; font-size: .75rem; font-weight: 750; }
.rank-item strong { display: block; margin-bottom: .28rem; font-size: .8rem; }
.rank-item b { font-size: .8rem; }
.rank-bar { display: block; width: 100%; height: .28rem; overflow: hidden; border-radius: 1rem; background: #eef2f3; }
.rank-bar i { display: block; height: 100%; border-radius: inherit; background: var(--teal); }
.bar-0 i { width: 2%; }.bar-1 i { width: 10%; }.bar-2 i { width: 20%; }.bar-3 i { width: 30%; }.bar-4 i { width: 40%; }.bar-5 i { width: 50%; }.bar-6 i { width: 60%; }.bar-7 i { width: 70%; }.bar-8 i { width: 80%; }.bar-9 i { width: 90%; }.bar-10 i { width: 100%; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .92rem 1rem; border-bottom: 1px solid #edf1f3; text-align: left; vertical-align: middle; }
th { color: var(--muted); background: #f8fafb; text-transform: uppercase; letter-spacing: .055em; font-size: .68rem; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfcfc; }
td { font-size: .84rem; }
td small { display: block; max-width: 22rem; margin-top: .25rem; overflow: hidden; color: var(--muted); text-overflow: ellipsis; }
code { font-size: .78rem; }
.sort-button { padding: 0; border-radius: 0; color: inherit; background: transparent; text-transform: inherit; letter-spacing: inherit; font-size: inherit; }
.sort-button:hover { color: var(--teal); background: transparent; }
.status { display: inline-flex; padding: .32rem .52rem; border-radius: 999px; font-size: .7rem; font-weight: 800; white-space: nowrap; }
.status.active { color: #067647; background: #ecfdf3; }
.status.waiting { color: #b54708; background: #fffaeb; }
.status.disabled { color: #475467; background: #f2f4f7; }
.actions { white-space: nowrap; }
.link-button { padding: .32rem; color: var(--teal); background: transparent; font-size: .78rem; }
.link-button:hover { color: var(--teal-dark); background: #eff8f7; }
.link-button.danger { color: var(--danger); }
.empty-state { padding: 3rem 1rem; color: var(--muted); text-align: center; }
.traffic-grid, .settings-grid, .guide-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.settings-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.setting-card { padding: 1.35rem; }
.setting-card p:last-child { margin: .8rem 0 0; color: var(--muted); line-height: 1.65; font-size: .86rem; }

.guide-banner { display: flex; align-items: flex-start; gap: 1rem; margin-bottom: 1.25rem; padding: 1.15rem 1.35rem; border: 1px solid #b6ece3; border-radius: .95rem; background: #eaf8f6; }
.guide-banner-icon { flex: 0 0 auto; display: grid; place-items: center; width: 2rem; height: 2rem; border-radius: 50%; color: white; background: var(--teal); font-weight: 850; }
.guide-banner h3 { margin: 0 0 .35rem; font-size: 1rem; color: #0b6058; }
.guide-banner p { margin: 0; color: #1e4d47; font-size: .88rem; line-height: 1.5; }
.guide-card-content { padding: .8rem 1.15rem 1.25rem; }
.guide-card-content p { font-size: .86rem; line-height: 1.55; }
.guide-steps { margin: .4rem 0 0; padding-left: 1.25rem; font-size: .86rem; line-height: 1.65; }
.guide-steps li { margin-bottom: .4rem; }

dialog { width: min(34rem, calc(100vw - 2rem)); padding: 0; border: 0; border-radius: 1.05rem; box-shadow: 0 25px 80px rgba(16,42,59,.3); }
dialog::backdrop { background: rgba(10,27,39,.62); }
dialog form, .snippet-dialog-body { padding: 1.5rem; }
.dialog-header, .dialog-actions, .toggle-row { display: flex; align-items: center; }
.dialog-header { justify-content: space-between; }
.dialog-header h2 { margin-bottom: 0; }
.icon-button { padding: .2rem .6rem; color: var(--muted); background: transparent; font-size: 1.8rem; }
.icon-button:hover { color: var(--navy); background: #f3f6f7; }
.dialog-actions { justify-content: flex-end; gap: .65rem; margin-top: 1.35rem; }
.toggle-row { gap: .6rem; }
.toggle-row input { width: auto; }
pre { overflow-x: auto; margin: 1rem 0; padding: 1rem; border-radius: .72rem; color: #d6e7ed; background: #102a3b; font-size: .78rem; line-height: 1.6; white-space: pre-wrap; }

@media (max-width: 1120px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .settings-grid { grid-template-columns: 1fr; }
  .analytics-toolbar { flex-wrap: wrap; }
  .range-group { margin-left: 0; }
}

@media (max-width: 790px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; padding: .72rem; flex-direction: row; align-items: center; overflow-x: auto; }
  .brand { margin: 0 .45rem 0 0; }
  .brand > span:last-child, .sidebar-foot { display: none; }
  .sidebar nav { display: flex; }
  .sidebar nav a { padding: .65rem .7rem; white-space: nowrap; }
  .sidebar nav a span { display: none; }
  .sidebar-logout { width: auto; margin-left: auto; white-space: nowrap; }
  .main-content { padding-top: 1.25rem; }
  .insight-grid, .traffic-grid, .guide-grid { grid-template-columns: 1fr; }
  .custom-range { width: 100%; }
  .header-actions .secondary { display: none; }
}

@media (max-width: 540px) {
  .page-header { align-items: flex-start; }
  .kpi-grid { grid-template-columns: 1fr; }
  .analytics-toolbar, .range-group { width: 100%; }
  .field-inline { width: 100%; }
  .range-group { display: grid; grid-template-columns: repeat(4, 1fr); }
  .range-button { padding: .55rem .3rem; }
  .custom-range { display: grid; grid-template-columns: 1fr 1fr; }
  .custom-range button { grid-column: 1 / -1; }
  .donut-layout { flex-direction: column; }
  .auth-card { padding: 1.5rem; }
}
