/* 5-Minute Day Planner */

:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --surface-2: #f0f0ed;
  --text: #1d1d1b;
  --text-2: #5f5f5a;
  --text-3: #8c8c85;
  --border: #deded8;
  --accent: #2f6fde;
  --accent-text: #ffffff;
  --danger: #c43d2f;
  --warn-bg: #fff4d6;
  --warn-text: #6b4e00;
  --now: #e5322d;
  --line-hour: #cfcfc8;
  --line-quarter: #e6e6e0;
  --line-slot: #f1f1ec;
  --block-default: #2f6fde;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.08), 0 4px 12px rgb(0 0 0 / 0.06);
  --radius: 6px;
  --slot-px: 12px;
  --gutter: 56px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161615;
    --surface: #1f1f1d;
    --surface-2: #2a2a27;
    --text: #ecece8;
    --text-2: #b0b0a8;
    --text-3: #85857d;
    --border: #3a3a36;
    --accent: #5b8ff0;
    --warn-bg: #3d3214;
    --warn-text: #f3d98b;
    --line-hour: #3f3f3a;
    --line-quarter: #2d2d2a;
    --line-slot: #242422;
    --block-default: #5b8ff0;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 4px 12px rgb(0 0 0 / 0.3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

button, input, select { font: inherit; color: inherit; }

button {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 5px 10px;
  cursor: pointer;
}
button:hover:not(:disabled) { background: var(--surface-2); }
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); }
button.icon { padding: 5px 9px; min-width: 32px; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

input[type="text"], input[type="email"], input[type="password"], input[type="date"] {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 8px;
}

#app { height: 100%; display: flex; flex-direction: column; }

/* ---------- Login ---------- */

.login {
  margin: auto;
  width: min(360px, calc(100% - 32px));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 28px 24px;
  box-shadow: var(--shadow);
}
.login h1 { margin: 0 0 4px; font-size: 20px; }
.login p { margin: 0 0 20px; color: var(--text-2); }
.login label { display: block; margin-bottom: 12px; font-weight: 500; }
.login input { display: block; width: 100%; margin-top: 4px; }
.login button { width: 100%; margin-top: 8px; padding: 8px; }
.login .error { color: var(--danger); margin: 8px 0 0; min-height: 1.4em; }

/* ---------- Shell ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.brand { font-weight: 650; margin-right: 8px; white-space: nowrap; }
.tabs { display: flex; gap: 2px; }
.tabs a {
  color: var(--text-2);
  text-decoration: none;
  padding: 6px 12px;
  border-radius: var(--radius);
}
.tabs a:hover { background: var(--surface-2); }
.tabs a[aria-current="page"] { background: var(--surface-2); color: var(--text); font-weight: 600; }
.spacer { flex: 1; }

.sync {
  font-size: 12px;
  color: var(--text-2);
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  white-space: nowrap;
}
.sync[data-state="offline"], .sync[data-state="error"] { background: var(--warn-bg); color: var(--warn-text); }

.menu { position: relative; }
.menu-list {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  min-width: 200px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 4px;
  z-index: 50;
}
.menu-list[hidden] { display: none; }
.menu-list button { display: block; width: 100%; text-align: left; border: 0; }
.menu-list .who { padding: 6px 10px; color: var(--text-3); font-size: 12px; border-bottom: 1px solid var(--border); margin-bottom: 4px; overflow-wrap: anywhere; }

.banner {
  padding: 8px 16px;
  background: var(--warn-bg);
  color: var(--warn-text);
  border-bottom: 1px solid var(--border);
}
.banner[hidden] { display: none; }

main { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }

.placeholder { margin: auto; text-align: center; color: var(--text-2); padding: 24px; }
.placeholder h2 { color: var(--text); margin: 0 0 6px; }

.toasts {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
  width: max-content;
  max-width: calc(100% - 32px);
}
.toast {
  background: var(--text);
  color: var(--bg);
  border-radius: 8px;
  padding: 8px 12px;
  box-shadow: var(--shadow);
  display: flex;
  gap: 12px;
  align-items: center;
}
.toast button { background: transparent; color: inherit; border-color: currentColor; padding: 2px 8px; }

/* ---------- Day ---------- */

.day-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.day-title { font-size: 16px; font-weight: 600; margin: 0 6px; min-width: 9em; }
.day-title .today-tag { font-size: 11px; font-weight: 600; color: var(--accent); margin-left: 6px; text-transform: uppercase; letter-spacing: 0.04em; }
.group { display: flex; gap: 4px; align-items: center; }
.group .label { color: var(--text-3); font-size: 12px; margin-right: 2px; }

.scroller { flex: 1; min-height: 0; overflow-y: auto; position: relative; overscroll-behavior: contain; }

.grid {
  position: relative;
  display: flex;
  margin: 0 16px 0 0;
  padding: 10px 0 24px;
}

.gutter { width: var(--gutter); flex: none; position: relative; }
.gutter .hour {
  position: absolute;
  right: 8px;
  transform: translateY(-50%);
  font-size: 11px;
  color: var(--text-3);
  white-space: nowrap;
}

.column {
  flex: 1;
  position: relative;
  border-left: 1px solid var(--line-hour);
  border-right: 1px solid var(--line-quarter);
  background-color: var(--surface);
  background-image:
    linear-gradient(to bottom, var(--line-hour) 1px, transparent 1px),
    linear-gradient(to bottom, var(--line-quarter) 1px, transparent 1px),
    linear-gradient(to bottom, var(--line-slot) 1px, transparent 1px);
  background-size:
    100% calc(var(--slot-px) * 12),
    100% calc(var(--slot-px) * 3),
    100% var(--slot-px);
  background-position: 0 var(--grid-offset, 0), 0 var(--grid-offset, 0), 0 0;
  cursor: crosshair;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}
.column.coarse {
  background-image:
    linear-gradient(to bottom, var(--line-hour) 1px, transparent 1px),
    linear-gradient(to bottom, var(--line-quarter) 1px, transparent 1px);
}
.column.readonly { cursor: default; }

.block {
  position: absolute;
  --c: var(--block-default);
  background: color-mix(in srgb, var(--c) 16%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--c) 45%, var(--surface));
  border-left: 4px solid var(--c);
  border-radius: 5px;
  padding: 2px 6px 2px 24px;
  overflow: hidden;
  cursor: grab;
  font-size: 12px;
  line-height: 1.25;
  min-height: 6px;
}
.block.dragging { cursor: grabbing; opacity: 0.92; box-shadow: var(--shadow); z-index: 20; }
.block.selected { outline: 2px solid var(--c); outline-offset: 1px; z-index: 10; }
.block.done { background: color-mix(in srgb, var(--c) 7%, var(--surface)); }
.block.done .block-title { text-decoration: line-through; color: var(--text-2); }
.block.ghost { opacity: 0.55; border-style: dashed; pointer-events: none; }
.column.readonly .block { cursor: default; }
.block-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.block-title.untitled { color: var(--text-3); font-weight: 500; font-style: italic; }
.block-time { color: var(--text-2); font-size: 11px; white-space: nowrap; }
.block.short { padding-top: 0; padding-bottom: 0; display: flex; gap: 6px; align-items: center; }
.block.short .block-time { display: none; }
.block.tiny { font-size: 10px; line-height: 1; }
.block-check {
  position: absolute;
  left: 4px;
  top: 3px;
  width: 15px;
  height: 15px;
  padding: 0;
  border: 1.5px solid color-mix(in srgb, var(--c) 70%, var(--text));
  border-radius: 4px;
  background: var(--surface);
  font-size: 10px;
  line-height: 1;
}
.block.short .block-check { top: 50%; transform: translateY(-50%); width: 12px; height: 12px; }
.block.done .block-check { background: var(--c); color: #fff; }
.handle { position: absolute; left: 0; right: 0; height: clamp(3px, 30%, 8px); cursor: ns-resize; z-index: 1; }
.handle.top { top: -1px; }
.handle.bottom { bottom: -1px; }
.column.readonly .handle { display: none; }
.block input.title-edit {
  width: 100%;
  font-size: 12px;
  font-weight: 600;
  padding: 0 2px;
  border: 1px solid var(--accent);
  border-radius: 3px;
  background: var(--surface);
}

.now-line {
  position: absolute;
  left: -6px;
  right: 0;
  height: 2px;
  background: var(--now);
  pointer-events: none;
  z-index: 15;
}
.now-line::before {
  content: "";
  position: absolute;
  left: 0;
  top: -4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--now);
}

.outside {
  position: absolute;
  left: 8px;
  z-index: 16;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
}
.outside.before { top: 4px; }
.outside.after { bottom: 4px; }

.day-hint { color: var(--text-3); font-size: 12px; padding: 6px 16px 0 calc(var(--gutter) + 8px); }

@media (max-width: 640px) {
  :root { --gutter: 46px; }
  .topbar { padding: 8px 12px; gap: 8px; }
  .brand { display: none; }
  .tabs a { padding: 6px 8px; }
  .day-toolbar { padding: 8px 12px; }
  .day-title { min-width: 0; }
  .zoom, .history { display: none; }
  .grid { margin-right: 12px; }
  .day-hint { display: none; }
}

@media print {
  .topbar, .day-toolbar, .banner, .toasts, .day-hint { display: none; }
  .scroller { overflow: visible; }
}
