:root {
  --ink: #202522;
  --muted: #67706a;
  --soft: #8b938d;
  --paper: #f4f2ed;
  --surface: #fffefa;
  --line: #deddd6;
  --line-soft: #ebe9e2;
  --forest: #245c46;
  --forest-dark: #174535;
  --forest-soft: #e1ece6;
  --amber: #95631f;
  --amber-soft: #f5ead8;
  --danger: #a73d32;
  --danger-soft: #f8e5e1;
  --shadow: 0 12px 35px rgba(36, 45, 39, .07);
  --radius: 14px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; color: var(--ink); background: var(--paper); font-family: "DM Sans", system-ui, sans-serif; line-height: 1.5; }
button, input { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, a:focus-visible { outline: 3px solid var(--forest); outline-offset: 3px; }
[hidden] { display: none !important; }

.skip-link { position: fixed; z-index: 100; top: 8px; left: 8px; padding: 10px 16px; background: var(--ink); color: #fff; border-radius: 8px; transform: translateY(-140%); }
.skip-link:focus { transform: translateY(0); }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 88px 24px 64px; position: relative; background: radial-gradient(circle at 50% 40%, #fbfaf6 0, #f4f2ed 48%, #ebe9e2 100%); }
.login-brand { position: absolute; top: 28px; left: 36px; display: flex; align-items: center; gap: 10px; font-weight: 600; }
.brand-mark { width: 34px; height: 34px; display: inline-grid; place-items: center; flex: none; border-radius: 50%; background: var(--forest); color: white; font-family: "Libre Franklin", sans-serif; font-size: 19px; }
.login-card { width: min(100%, 480px); padding: 48px; background: rgba(255,254,250,.92); border: 1px solid rgba(222,221,214,.85); border-radius: 20px; box-shadow: var(--shadow); backdrop-filter: blur(10px); }
.eyebrow { margin: 0 0 6px; color: var(--forest); font-size: 12px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; }
.login-card h1 { margin: 0; font: 600 35px/1.2 "Libre Franklin", sans-serif; letter-spacing: -.035em; }
.login-copy { margin: 18px 0 28px; color: var(--muted); }
label { display: block; margin-bottom: 8px; font-size: 14px; font-weight: 600; }
.password-wrap { position: relative; }
input[type=password], input[type=text] { width: 100%; min-height: 48px; padding: 11px 72px 11px 14px; border: 1px solid #c9cbc5; border-radius: 9px; background: #fff; }
input:focus { border-color: var(--forest); }
.reveal-button { position: absolute; top: 2px; right: 5px; min-width: 58px; min-height: 44px; border: 0; background: transparent; color: var(--forest); cursor: pointer; font-size: 13px; font-weight: 600; border-radius: 6px; }
.field-error { min-height: 21px; margin: 6px 0; color: var(--danger); font-size: 13px; }
.security-note { margin: 18px 0 0; color: var(--muted); font-size: 12px; text-align: center; }
.lock-icon { font-size: 9px; color: var(--forest); }
.login-footer { position: absolute; bottom: 24px; color: var(--muted); font-size: 12px; }

.button { display: inline-flex; min-height: 44px; padding: 9px 16px; border: 1px solid transparent; border-radius: 8px; align-items: center; justify-content: center; gap: 8px; font-weight: 600; font-size: 14px; cursor: pointer; transition: .16s ease; }
.button:hover:not(:disabled) { transform: translateY(-1px); }
.button:disabled { opacity: .48; cursor: not-allowed; }
.button-primary { background: var(--forest); color: white; box-shadow: 0 5px 12px rgba(36,92,70,.14); }
.button-primary:hover:not(:disabled) { background: var(--forest-dark); }
.button-secondary { background: var(--surface); border-color: #cfd1cb; }
.button-secondary:hover:not(:disabled), .button-quiet:hover:not(:disabled) { background: #f1f0eb; }
.button-quiet { background: transparent; border-color: var(--line); }
.button-wide { width: 100%; }
.button-small { min-height: 36px; padding: 6px 12px; }

.topbar { height: 72px; padding: 0 max(24px, calc((100vw - 1240px) / 2)); display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 32px; background: rgba(255,254,250,.92); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; backdrop-filter: blur(12px); }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-weight: 600; }
.topbar nav { align-self: stretch; display: flex; gap: 28px; }
.nav-link { display: flex; align-items: center; color: var(--muted); text-decoration: none; font-size: 14px; border-bottom: 2px solid transparent; }
.nav-link:hover, .nav-link.active { color: var(--ink); border-bottom-color: var(--forest); }
.header-actions { justify-self: end; display: flex; align-items: center; gap: 10px; }
.connection { display: inline-flex; align-items: center; gap: 7px; margin-right: 3px; color: var(--muted); font-size: 12px; }
.connection-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--soft); }
.connection.online .connection-dot { background: #2f8a5f; box-shadow: 0 0 0 4px #e4f2ea; }
.connection.offline .connection-dot { background: var(--danger); }
.icon-button { width: 42px; height: 42px; border: 1px solid var(--line); background: transparent; border-radius: 8px; font-size: 20px; cursor: pointer; }
.icon-button.loading { animation: spin 1s linear infinite; }

main { max-width: 1240px; margin: 0 auto; padding: 52px 24px 64px; }
.hero { display: flex; justify-content: space-between; align-items: end; margin-bottom: 32px; gap: 24px; }
.hero h1 { margin: 0; font: 600 clamp(32px, 4vw, 46px)/1.13 "Libre Franklin", sans-serif; letter-spacing: -.04em; }
.hero-subtitle { margin: 10px 0 0; color: var(--muted); }
.page-error { margin-bottom: 20px; padding: 14px 16px; display: flex; justify-content: space-between; align-items: center; gap: 16px; border: 1px solid #ecc8c2; background: var(--danger-soft); border-radius: 10px; color: #7d2c25; }
.page-error p { margin: 2px 0 0; font-size: 13px; }

.metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 20px; }
.metric-card, .panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 3px 14px rgba(36,45,39,.025); }
.metric-card { min-height: 152px; padding: 19px 20px; }
.metric-top { min-height: 27px; display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: 13px; }
.metric-icon { color: var(--forest); font-size: 20px; }
.metric-value { margin: 18px 0 2px; font: 600 25px/1.2 "Libre Franklin", sans-serif; letter-spacing: -.03em; }
.metric-unit { margin-left: 5px; color: var(--soft); font: 400 13px "DM Sans", sans-serif; }
.metric-detail { margin: 4px 0 0; color: var(--soft); font-size: 12px; }
.status-pill { padding: 4px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.status-pill.positive { color: var(--forest-dark); background: var(--forest-soft); }
.status-pill.warning { color: #704716; background: var(--amber-soft); }
.status-pill.neutral { color: #565d58; background: #ecece7; }
.capacity-track { height: 4px; margin: 12px 0 7px; background: #e5e7e2; border-radius: 4px; overflow: hidden; }
.capacity-track span { display: block; width: 0; height: 100%; background: var(--forest); transition: width .3s ease; }

.content-grid { display: grid; grid-template-columns: minmax(0, 1.72fr) minmax(280px, .8fr); gap: 20px; align-items: stretch; }
.panel { padding: 24px; }
.panel-heading { min-height: 53px; display: flex; justify-content: space-between; align-items: start; gap: 20px; }
.panel h2 { margin: 0; font: 600 20px/1.3 "Libre Franklin", sans-serif; letter-spacing: -.025em; }
.count-badge { min-width: 28px; height: 28px; display: grid; place-items: center; border-radius: 50%; background: var(--forest-soft); color: var(--forest); font-weight: 600; font-size: 12px; }
.appointment-list { margin: 18px 0 0; padding: 0; list-style: none; }
.appointment-item { display: grid; grid-template-columns: 54px 1fr auto; align-items: center; gap: 16px; padding: 16px 0; border-top: 1px solid var(--line-soft); }
.date-block { width: 52px; padding: 7px 3px; text-align: center; border-radius: 9px; background: #f0efea; }
.date-block span { display: block; color: var(--forest); font-size: 10px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; }
.date-block strong { display: block; margin-top: -1px; font: 600 21px "Libre Franklin", sans-serif; }
.appointment-main strong { display: block; font-size: 14px; }
.appointment-main p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.confirmed-label { display: inline-flex; gap: 5px; align-items: center; color: var(--forest); font-size: 11px; font-weight: 600; }
.confirmed-label::before { content: "✓"; width: 18px; height: 18px; display: grid; place-items: center; color: white; background: var(--forest); border-radius: 50%; font-size: 10px; }

.control-status { display: flex; gap: 12px; margin: 18px 0; padding: 15px; background: var(--forest-soft); border-radius: 10px; }
.control-status.warning { background: var(--amber-soft); }
.control-icon { color: var(--forest); }
.control-status strong, .import-block strong { font-size: 14px; }
.control-status p, .import-block p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.control-capacity { margin-top: 18px; }
.control-capacity label { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 600; }
.control-capacity select { width: 100%; min-height: 42px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: white; color: var(--ink); }
.control-capacity p { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.divider { height: 1px; margin: 22px 0; background: var(--line-soft); }
.import-block .button-file { margin-top: 14px; }
.selected-file { min-height: 20px; overflow-wrap: anywhere; }

.activity-panel { margin-top: 20px; }
.text-button { min-height: 40px; padding: 5px 8px; border: 0; background: transparent; color: var(--forest); font-weight: 600; cursor: pointer; }
.timeline { margin: 18px 0 0; padding: 0; list-style: none; }
.timeline-item { display: grid; grid-template-columns: 20px minmax(0,1fr) auto; gap: 14px; position: relative; padding: 0 0 22px; }
.timeline-item:last-child { padding-bottom: 0; }
.timeline-item:not(:last-child)::before { content: ""; position: absolute; left: 9px; top: 19px; bottom: 0; width: 1px; background: var(--line); }
.timeline-dot { z-index: 1; width: 19px; height: 19px; display: grid; place-items: center; border-radius: 50%; background: var(--forest-soft); color: var(--forest); font-size: 10px; }
.timeline-dot.warning { background: var(--amber-soft); color: var(--amber); }
.timeline-dot.error { background: var(--danger-soft); color: var(--danger); }
.timeline-copy strong { display: block; font-size: 14px; }
.timeline-copy p { margin: 2px 0 0; color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.timeline time { color: var(--soft); font-size: 12px; white-space: nowrap; }
.loading-state, .empty-state { min-height: 130px; display: flex; align-items: center; justify-content: center; gap: 10px; color: var(--soft); font-size: 13px; text-align: center; }
.spinner { width: 17px; height: 17px; border: 2px solid #d7dad5; border-top-color: var(--forest); border-radius: 50%; animation: spin .8s linear infinite; }
.last-updated { margin: 16px 0 0; color: var(--soft); text-align: right; font-size: 11px; }

.modal-backdrop { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px; background: rgba(25,31,27,.48); backdrop-filter: blur(3px); }
.modal { width: min(100%, 440px); padding: 30px; background: var(--surface); border-radius: 16px; box-shadow: 0 20px 50px rgba(20,25,22,.2); }
.modal-icon { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 50%; background: var(--amber-soft); color: var(--amber); font-weight: 600; }
.modal h2 { margin: 18px 0 8px; font: 600 22px "Libre Franklin", sans-serif; }
.modal p { margin: 0; color: var(--muted); }
.modal-actions { display: flex; justify-content: end; gap: 10px; margin-top: 26px; }
.toast-region { position: fixed; z-index: 60; right: 20px; bottom: 20px; display: grid; gap: 8px; }
.toast { width: min(360px, calc(100vw - 40px)); padding: 13px 16px; color: white; background: #26352e; border-radius: 9px; box-shadow: var(--shadow); font-size: 13px; animation: toast-in .2s ease; }
.toast.error { background: #7d2c25; }

@keyframes spin { to { transform: rotate(360deg); } }
.plan-panel { margin-top: 18px; }
.plan-list { list-style: none; padding: 0; margin: 4px 0 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.plan-item { border: 1px solid var(--border); border-radius: 10px; padding: 13px 14px; background: var(--surface-soft); }
.plan-item > div { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.plan-item strong { color: var(--ink); }
.plan-item span, .plan-item p { color: var(--muted); font-size: 12px; }
.plan-item p { margin: 7px 0 0; line-height: 1.4; }
.classification-label { font-weight: 700; color: var(--blue) !important; }
.plan-state { text-transform: capitalize; }
.warning-state { color: var(--warning, #8a4b08); }

@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

@media (max-width: 900px) {
  .topbar { grid-template-columns: 1fr auto; padding: 0 20px; }
  .topbar nav { display: none; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .content-grid { grid-template-columns: 1fr; }
  .plan-list { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .login-shell { padding: 72px 16px 56px; align-items: center; }
  .login-brand { top: 20px; left: 20px; }
  .login-card { padding: 30px 22px; border-radius: 14px; }
  .login-card h1 { font-size: 29px; }
  .topbar { height: 64px; }
  .topbar .brand > span:last-child, .connection span:last-child, #logout-button { display: none; }
  .header-actions { gap: 7px; }
  main { padding: 34px 16px 48px; }
  .hero { align-items: start; flex-direction: column; margin-bottom: 24px; }
  .hero .button { width: 100%; }
  .metrics { grid-template-columns: 1fr 1fr; gap: 8px; }
  .metric-card { min-height: 142px; padding: 16px; }
  .metric-value { font-size: 21px; }
  .panel { padding: 20px 16px; }
  .appointment-item { grid-template-columns: 48px 1fr; gap: 12px; }
  .date-block { width: 46px; }
  .confirmed-label { grid-column: 2; justify-self: start; margin-top: -8px; }
  .timeline-item { grid-template-columns: 20px minmax(0,1fr); }
  .timeline time { grid-column: 2; margin-top: -8px; }
  .page-error { align-items: start; flex-direction: column; }
}
@media (max-width: 390px) {
  .metrics { grid-template-columns: 1fr; }
  .metric-card { min-height: auto; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
