* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { color-scheme: light; background: var(--kagent-soft); }
body { margin: 0; min-width: 320px; color: var(--kagent-ink); background: var(--kagent-soft); font: 400 15px/1.55 var(--kagent-font); }
button, input { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, a:focus-visible { outline: none; box-shadow: var(--kagent-focus); }

.app-header { position: sticky; top: 0; z-index: 20; height: 78px; background: rgba(255,255,255,.97); border-bottom: 1px solid var(--kagent-line); }
.app-header__inner { height: 100%; display: flex; align-items: center; justify-content: space-between; gap: 24px; }
.brand { display: inline-flex; align-items: center; gap: 18px; color: var(--kagent-navy-dark); text-decoration: none; font-weight: 700; }
.brand img { width: 132px; height: auto; }
.brand span { padding-left: 18px; border-left: 1px solid var(--kagent-line); }
.header-actions { display: flex; align-items: center; gap: 16px; }
.header-actions form { margin: 0; }
.sync-status { display: inline-flex; align-items: center; gap: 8px; color: var(--kagent-muted); font-size: 13px; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--kagent-success); box-shadow: 0 0 0 4px rgba(22,130,87,.1); }
.status-dot--warning { background: var(--kagent-orange); box-shadow: 0 0 0 4px rgba(255,107,0,.1); }
.icon-button { width: 44px; height: 44px; display: grid; place-items: center; border: 1px solid var(--kagent-line); background: #fff; color: var(--kagent-navy); }
.icon-button:hover { border-color: var(--kagent-navy); }
.icon-button i { font-size: 21px; }

.dashboard { padding-block: 54px 82px; }
.dashboard-intro { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 48px; padding: 44px 48px; color: white; background: var(--kagent-navy-dark); border-left: 5px solid var(--kagent-orange); }
.dashboard-intro .kagent-eyebrow { color: #ff9a52; }
.dashboard-intro .kagent-heading { max-width: 720px; color: #fff; font-size: clamp(42px, 5vw, 72px); line-height: 1; }
.intro-copy { max-width: 650px; margin: 18px 0 0; color: #c8d3e1; font-size: 17px; }
.day-score__ring { position: relative; width: 148px; height: 148px; display: grid; place-items: center; text-align: center; }
.day-score__ring svg { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.day-score__ring circle { fill: none; stroke-width: 10; }
.score-track { stroke: rgba(255,255,255,.16); }
.score-progress { stroke: var(--kagent-orange); stroke-linecap: round; stroke-dasharray: 100; stroke-dashoffset: 100; transition: stroke-dashoffset .2s ease; }
.day-score__ring > div { position: relative; z-index: 1; }
.day-score__ring strong { display: block; color: #fff; font-size: 31px; line-height: 1; }
.day-score__ring span { display: block; margin-top: 7px; color: #c8d3e1; font-size: 12px; }

.control-bar { margin-top: 20px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 14px; background: #fff; border: 1px solid var(--kagent-line); }
.range-tabs { display: flex; align-items: center; }
.range-tabs button { min-height: 44px; padding: 0 17px; border: 0; border-right: 1px solid var(--kagent-line); color: var(--kagent-muted); background: #fff; font-weight: 600; }
.range-tabs button:last-child { border-right: 0; }
.range-tabs button:hover { color: var(--kagent-navy); background: var(--kagent-soft); }
.range-tabs button.is-active { color: #fff; background: var(--kagent-navy); }
.date-controls { display: flex; align-items: end; gap: 10px; }
.date-controls label { display: grid; gap: 3px; color: var(--kagent-muted); font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.date-controls input { height: 40px; padding: 0 10px; color: var(--kagent-ink); background: #fff; border: 1px solid var(--kagent-line); }
.refresh-button { min-height: 40px; display: inline-flex; align-items: center; gap: 8px; padding: 0 14px; color: var(--kagent-navy); background: #fff; border: 1px solid var(--kagent-navy); font-weight: 700; }
.refresh-button:hover { color: #fff; background: var(--kagent-navy); }
.is-spinning { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.metric-grid { display: grid; grid-template-columns: repeat(4, 1fr); margin-top: 20px; background: #fff; border: 1px solid var(--kagent-line); }
.metric { min-height: 138px; display: flex; align-items: center; gap: 18px; padding: 25px 24px; border-right: 1px solid var(--kagent-line); }
.metric:last-child { border-right: 0; }
.metric > i { flex: 0 0 auto; color: var(--kagent-orange); font-size: 32px; }
.metric span, .metric small { display: block; color: var(--kagent-muted); }
.metric span { font-size: 12px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; }
.metric strong { display: block; margin: 3px 0 1px; color: var(--kagent-navy-dark); font-size: 29px; line-height: 1; }
.metric small { font-size: 11px; }
.metric--primary { background: #fffaf6; box-shadow: inset 0 -3px var(--kagent-orange); }

.dashboard-grid { display: grid; gap: 20px; margin-top: 20px; }
.dashboard-grid--top { grid-template-columns: minmax(320px, .85fr) minmax(460px, 1.35fr); }
.dashboard-grid--bottom { grid-template-columns: minmax(480px, 1.25fr) minmax(330px, .75fr); }
.panel { min-width: 0; padding: 28px; background: #fff; border: 1px solid var(--kagent-line); }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.panel-heading h2, .quality-panel h2 { margin: 5px 0 0; color: var(--kagent-navy-dark); font-size: 24px; line-height: 1.15; letter-spacing: -.025em; }
.panel-counter, .panel-context { color: var(--kagent-muted); font-size: 12px; font-weight: 700; }
.panel-counter { padding: 6px 9px; color: var(--kagent-success); background: rgba(22,130,87,.08); }

.routine-list { display: grid; gap: 1px; background: var(--kagent-line); }
.routine-row { min-height: 58px; display: grid; grid-template-columns: 26px 1fr auto; align-items: center; gap: 12px; padding: 11px 13px; background: #fff; }
.routine-row__status { width: 21px; height: 21px; display: grid; place-items: center; border: 1.5px solid #c5ccd5; border-radius: 50%; color: transparent; }
.routine-row--done .routine-row__status { color: #fff; background: var(--kagent-success); border-color: var(--kagent-success); }
.routine-row__status i { font-size: 13px; font-weight: 700; }
.routine-row__name { overflow: hidden; color: var(--kagent-ink); font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.routine-row--done .routine-row__name { color: var(--kagent-muted); }
.art-label { color: var(--kagent-muted); font-size: 10px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.empty-state { padding: 30px 20px; color: var(--kagent-muted); text-align: center; background: #fff; }

.trend-chart { height: 270px; display: flex; align-items: stretch; gap: 8px; padding-top: 14px; border-bottom: 1px solid var(--kagent-line); }
.trend-day { flex: 1 1 0; min-width: 11px; display: grid; grid-template-rows: 1fr 28px; gap: 8px; text-align: center; }
.trend-bar-track { position: relative; min-height: 0; display: flex; align-items: flex-end; overflow: hidden; }
.trend-bar { width: 100%; min-height: 2px; background: var(--kagent-navy); }
.trend-bar--today { background: var(--kagent-orange); }
.trend-rate-0 { height: 0; }
.trend-rate-5 { height: 5%; }
.trend-rate-10 { height: 10%; }
.trend-rate-15 { height: 15%; }
.trend-rate-20 { height: 20%; }
.trend-rate-25 { height: 25%; }
.trend-rate-30 { height: 30%; }
.trend-rate-35 { height: 35%; }
.trend-rate-40 { height: 40%; }
.trend-rate-45 { height: 45%; }
.trend-rate-50 { height: 50%; }
.trend-rate-55 { height: 55%; }
.trend-rate-60 { height: 60%; }
.trend-rate-65 { height: 65%; }
.trend-rate-70 { height: 70%; }
.trend-rate-75 { height: 75%; }
.trend-rate-80 { height: 80%; }
.trend-rate-85 { height: 85%; }
.trend-rate-90 { height: 90%; }
.trend-rate-95 { height: 95%; }
.trend-rate-100 { height: 100%; }
.trend-day span { color: var(--kagent-muted); font-size: 10px; white-space: nowrap; }
.trend-day[title] { cursor: help; }

.matrix-panel { margin-top: 20px; }
.matrix-heading { align-items: end; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; color: var(--kagent-muted); font-size: 11px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend-box { width: 12px; height: 12px; display: inline-block; }
.legend-box--done { background: var(--kagent-success); }
.legend-box--open { background: #f3c39e; }
.legend-box--none { background: var(--kagent-soft); border: 1px solid var(--kagent-line); }
.matrix-scroll { overflow-x: auto; overscroll-behavior-inline: contain; }
.routine-matrix { width: 100%; min-width: 680px; border-collapse: collapse; }
.routine-matrix th, .routine-matrix td { padding: 8px 5px; border-bottom: 1px solid #edf0f3; text-align: center; }
.routine-matrix thead th { color: var(--kagent-muted); font-size: 9px; font-weight: 700; text-transform: uppercase; }
.routine-matrix th:first-child { position: sticky; left: 0; z-index: 2; width: 230px; padding-left: 0; background: #fff; text-align: left; }
.routine-matrix tbody th { color: var(--kagent-ink); font-size: 12px; font-weight: 600; }
.matrix-cell { width: 22px; height: 22px; display: inline-grid; place-items: center; border: 1px solid transparent; }
.matrix-cell--done { color: #fff; background: var(--kagent-success); }
.matrix-cell--open { color: #9a4a0e; background: #fde5d3; border-color: #f3c39e; }
.matrix-cell--none { background: var(--kagent-soft); border-color: #edf0f3; }
.matrix-cell i { font-size: 12px; }

.ranking-list { display: grid; gap: 18px; }
.ranking-row { display: grid; grid-template-columns: minmax(140px, 1fr) minmax(100px, 1.2fr) 54px; align-items: center; gap: 16px; }
.ranking-row__name { min-width: 0; }
.ranking-row__name strong, .ranking-row__name small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ranking-row__name strong { color: var(--kagent-ink); font-size: 13px; }
.ranking-row__name small { color: var(--kagent-muted); font-size: 10px; }
.ranking-progress { width: 100%; height: 8px; display: block; appearance: none; border: 0; background: var(--kagent-soft); }
.ranking-progress::-webkit-progress-bar { background: var(--kagent-soft); }
.ranking-progress::-webkit-progress-value { background: var(--kagent-navy); }
.ranking-progress::-moz-progress-bar { background: var(--kagent-navy); }
.ranking-row:first-child .ranking-progress::-webkit-progress-value { background: var(--kagent-success); }
.ranking-row:first-child .ranking-progress::-moz-progress-bar { background: var(--kagent-success); }
.ranking-rate { color: var(--kagent-navy-dark); text-align: right; font-weight: 700; }

.quality-panel { color: #c8d3e1; background: var(--kagent-navy-dark); border-color: var(--kagent-navy-dark); }
.quality-panel .kagent-eyebrow { color: #ff9a52; }
.quality-panel h2 { max-width: 410px; color: #fff; font-size: 28px; }
.quality-panel > p:not(.kagent-eyebrow) { margin: 15px 0 24px; }
.quality-icon { width: 52px; height: 52px; display: grid; place-items: center; margin-bottom: 30px; color: var(--kagent-orange); background: rgba(255,255,255,.08); }
.quality-icon i { font-size: 28px; }
.quality-panel dl { margin: 0; border-top: 1px solid rgba(255,255,255,.18); }
.quality-panel dl div { display: flex; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid rgba(255,255,255,.12); }
.quality-panel dt { color: #c8d3e1; }
.quality-panel dd { margin: 0; color: #fff; font-weight: 700; }

.error-banner { position: fixed; right: 24px; bottom: 24px; z-index: 30; max-width: 520px; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 14px; padding: 18px; color: #fff; background: #7a2d16; box-shadow: var(--kagent-workflow-shadow); }
.error-banner > i { font-size: 24px; }
.error-banner strong, .error-banner span { display: block; }
.error-banner span { color: #f7d8cd; font-size: 12px; }
.error-banner button { min-height: 38px; color: #7a2d16; background: #fff; border: 0; font-weight: 700; }
.app-footer { color: #c8d3e1; background: #07182f; }
.app-footer > div { min-height: 78px; display: flex; align-items: center; justify-content: space-between; gap: 20px; font-size: 12px; }

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 32px; color: #fff; background: var(--kagent-navy-dark); }
.login-shell { width: min(100%, 1010px); display: grid; grid-template-columns: 1fr 420px; gap: 72px; align-items: center; }
.login-brand img { width: 176px; height: auto; margin-bottom: 64px; filter: brightness(0) invert(1); }
.login-brand .kagent-eyebrow { color: #ff9a52; }
.login-brand h1 { margin-top: 12px; color: #fff; font-size: clamp(48px, 6vw, 78px); line-height: 1; }
.login-brand > p:last-child { max-width: 520px; color: #c8d3e1; font-size: 17px; }
.login-card { position: relative; padding: 42px; color: var(--kagent-ink); background: #fff; box-shadow: var(--kagent-workflow-shadow); }
.login-card__marker { position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--kagent-orange); }
.login-card h2 { margin: 8px 0 28px; color: var(--kagent-navy-dark); font-size: 29px; }
.login-card form { display: grid; gap: 10px; }
.login-card label { margin-top: 6px; color: var(--kagent-muted); font-size: 12px; font-weight: 700; }
.login-card input { min-height: 50px; padding: 0 13px; color: var(--kagent-ink); border: 1px solid var(--kagent-line); }
.login-card button { margin-top: 14px; border: 0; }
.login-note { margin: 18px 0 0; color: var(--kagent-muted); font-size: 11px; text-align: center; }
.login-error { padding: 10px 12px; color: #8b2818; background: #fff0ea; border-left: 3px solid #b33b22; font-size: 12px; }

@media (max-width: 1040px) {
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .metric:nth-child(2) { border-right: 0; }
  .metric:nth-child(-n+2) { border-bottom: 1px solid var(--kagent-line); }
  .dashboard-grid--top, .dashboard-grid--bottom { grid-template-columns: 1fr; }
  .login-shell { gap: 44px; }
}

@media (max-width: 900px) {
  .app-header { height: 72px; }
  .brand span { display: none; }
  .sync-status span:last-child { display: none; }
  .dashboard { padding-block: 34px 68px; }
  .dashboard-intro { padding: 36px; }
  .control-bar { align-items: stretch; flex-direction: column; }
  .date-controls { justify-content: flex-end; }
  .login-shell { grid-template-columns: 1fr; max-width: 560px; }
  .login-brand { display: none; }
}

@media (max-width: 620px) {
  .brand img { width: 116px; }
  .header-actions { gap: 10px; }
  .dashboard-intro { grid-template-columns: 1fr; gap: 28px; padding: 30px 24px; }
  .dashboard-intro .kagent-heading { font-size: 43px; }
  .intro-copy { font-size: 15px; }
  .day-score__ring { width: 112px; height: 112px; }
  .range-tabs { display: grid; grid-template-columns: repeat(4, 1fr); }
  .range-tabs button { padding: 0 8px; font-size: 12px; }
  .date-controls { display: grid; grid-template-columns: 1fr 1fr; }
  .date-controls input { width: 100%; }
  .refresh-button { grid-column: 1 / -1; justify-content: center; }
  .metric-grid { grid-template-columns: 1fr; }
  .metric, .metric:nth-child(2) { min-height: 104px; border-right: 0; border-bottom: 1px solid var(--kagent-line); }
  .metric:last-child { border-bottom: 0; }
  .panel { padding: 22px 18px; }
  .matrix-heading { align-items: flex-start; flex-direction: column; }
  .ranking-row { grid-template-columns: minmax(120px, 1fr) 72px; }
  .ranking-progress { grid-column: 1 / -1; grid-row: 2; }
  .error-banner { right: 14px; bottom: 14px; left: 14px; grid-template-columns: auto 1fr; }
  .error-banner button { grid-column: 1 / -1; }
  .app-footer > div { align-items: flex-start; flex-direction: column; justify-content: center; }
  .login-page { padding: 16px; }
  .login-card { padding: 34px 24px; }
}

@media (prefers-reduced-motion: reduce) {
  .score-progress { transition: none; }
  .is-spinning { animation: none; }
}
