:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #eef1f7;
  --text: #131722;
  --muted: #5b6577;
  --border: #dfe4ee;
  --primary: #2f5fe0;
  --primary-ink: #ffffff;
  --free: #1d8a4e;
  --free-soft: #e3f6ea;
  --busy: #c23c2f;
  --busy-soft: #fdeae7;
  --mine: #8a5a12;
  --mine-soft: #fdf2df;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(19, 23, 34, .06), 0 8px 24px rgba(19, 23, 34, .06);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1020;
    --surface: #151b30;
    --surface-2: #1d2540;
    --text: #eef1f8;
    --muted: #9aa5bd;
    --border: #27304d;
    --primary: #5b87f5;
    --primary-ink: #0b1020;
    --free: #4ade80;
    --free-soft: #10301f;
    --busy: #fb7185;
    --busy-soft: #3a1620;
    --mine: #fbbf24;
    --mine-soft: #3a2c0f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  padding: max(12px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right))
           max(16px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
}

.view { max-width: 560px; margin: 0 auto; }
[hidden] { display: none !important; }

h1 { font-size: 1.35rem; margin: 0; letter-spacing: -.01em; }
h2 { font-size: .95rem; margin: 0 0 8px; letter-spacing: .01em; }
p { margin: 0; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.eyebrow {
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--muted);
  margin-bottom: 2px;
}

/* ---------------------------------------------------------------- login */

#login-view { display: grid; place-items: center; min-height: 88dvh; }

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 22px;
  width: 100%;
  text-align: center;
}

.logo { margin-bottom: 12px; }
.logo img { border-radius: 14px; }

#login-form { margin-top: 22px; text-align: left; }

label {
  display: block;
  font-size: .82rem;
  font-weight: 600;
  color: var(--muted);
  margin: 14px 0 6px;
}

input {
  width: 100%;
  padding: 13px 14px;
  font-size: 1rem;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  transition: border-color .15s, box-shadow .15s;
}

input:focus-visible {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 22%, transparent);
}

.error {
  margin-top: 12px;
  color: var(--busy);
  font-size: .88rem;
  font-weight: 500;
}

/* ---------------------------------------------------------------- buttons */

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 13px 16px;
  font-size: .95rem;
  font-weight: 600;
  font-family: inherit;
  color: var(--text);
  background: var(--surface-2);
  cursor: pointer;
  transition: transform .08s, filter .15s, background .15s;
  touch-action: manipulation;
}

.btn:active { transform: scale(.975); }
.btn:disabled { opacity: .55; cursor: default; transform: none; }
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.btn.primary { background: var(--primary); color: var(--primary-ink); }
.btn.ghost { background: transparent; border-color: var(--border); }
.btn.danger { background: var(--busy-soft); color: var(--busy); border-color: transparent; }
.btn.small { padding: 8px 12px; font-size: .85rem; border-radius: 10px; }
.btn.block { width: 100%; margin-top: 20px; }

/* ---------------------------------------------------------------- topbar */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

/* ---------------------------------------------------------------- status */

.status-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 14px;
}

.status-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  padding: 6px 11px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
}

.badge::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.badge.free { background: var(--free-soft); color: var(--free); }
.badge.busy { background: var(--busy-soft); color: var(--busy); }
.badge.mine { background: var(--mine-soft); color: var(--mine); }

.conn { font-size: .6rem; color: var(--free); transition: color .3s; }
.conn.offline { color: var(--muted); }

.status-title {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -.02em;
  line-height: 1.25;
}

.status-sub { color: var(--muted); font-size: .92rem; margin-top: 6px; }

.progress {
  margin-top: 16px;
  height: 6px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  border-radius: 999px;
  background: var(--busy);
  transition: width 1s linear;
}

.progress-bar.mine { background: var(--mine); }

/* ---------------------------------------------------------------- actions */

.actions { display: grid; gap: 10px; margin-bottom: 14px; }

.actions .group {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(72px, 1fr));
  gap: 8px;
}

.actions .label {
  font-size: .78rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: -2px;
}

/* ---------------------------------------------------------------- panels */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }

.list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: .9rem;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.list li:last-child { border-bottom: none; padding-bottom: 0; }
.list .who { font-weight: 600; }
.list .when { color: var(--muted); font-size: .85rem; }
.list .note { color: var(--muted); font-size: .8rem; font-style: italic; }
.muted-list li { color: var(--muted); }

.footer { text-align: center; margin: 18px 0 4px; }

/* ---------------------------------------------------------------- sheet */

.sheet {
  border: none;
  border-radius: 18px 18px 0 0;
  padding: 22px 20px calc(22px + env(safe-area-inset-bottom));
  background: var(--surface);
  color: var(--text);
  width: 100%;
  max-width: 560px;
  margin: auto auto 0;
  box-shadow: var(--shadow);
}

.sheet::backdrop { background: rgba(6, 9, 18, .55); }
.sheet h2 { font-size: 1.1rem; margin-bottom: 4px; }
.sheet-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 22px; }

/* ---------------------------------------------------------------- toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: min(90vw, 420px);
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  font-size: .88rem;
  font-weight: 500;
  box-shadow: var(--shadow);
  z-index: 50;
  animation: rise .18s ease-out;
}

.toast.error { background: var(--busy); color: #fff; }

@keyframes rise {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001s !important; transition-duration: .001s !important; }
}
