:root {
  --bg-base: #020617;
  --bg-surface: #0f172a;
  --bg-cell: #1e293b;
  --bg-cell-hover: #233148;
  --border: #334155;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-tint: rgba(59, 130, 246, 0.08);
  --accent-border: rgba(59, 130, 246, 0.4);
  --success: #10b981;
  --danger: #f43f5e;
  --danger-hover: #e11d48;

  --radius: 8px;
  --radius-lg: 12px;
  --shadow-modal: 0 20px 50px rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg-base);
  color: var(--text-primary);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-feature-settings: "tnum" 1;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
  padding: 0;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.muted {
  color: var(--text-muted);
}

.error {
  color: var(--danger);
  font-size: 14px;
  margin: 8px 0 0;
}

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

.btn-primary,
.btn-ghost,
.btn-danger {
  height: 44px;
  padding: 0 20px;
  border-radius: var(--radius);
  font-weight: 500;
  transition: background-color 150ms ease;
  min-width: 88px;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-ghost {
  color: var(--text-secondary);
}
.btn-ghost:hover {
  background: var(--bg-cell);
}

.btn-danger {
  color: var(--danger);
}
.btn-danger:hover {
  background: rgba(244, 63, 94, 0.12);
}

.icon-btn {
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  border-radius: var(--radius);
  font-size: 20px;
  transition: color 150ms, background-color 150ms;
}
.icon-btn:hover {
  color: var(--text-primary);
  background: var(--bg-cell);
}

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

.login {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 16px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.login-card h1 {
  margin: 0 0 8px;
  font-size: 24px;
  font-weight: 600;
  text-align: center;
}

.login-card input {
  background: var(--bg-cell);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: var(--radius);
  padding: 0 14px;
  height: 44px;
  font-size: 16px;
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding-top: max(12px, env(safe-area-inset-top));
}

.brand {
  font-weight: 600;
  font-size: 18px;
  flex-shrink: 0;
}

.month-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 0 auto;
}

.month-label {
  font-weight: 600;
  font-size: 16px;
  padding: 8px 12px;
  color: var(--text-primary);
  border-radius: var(--radius);
}
.month-label:hover {
  background: var(--bg-cell);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.month-total {
  color: var(--text-secondary);
  font-size: 14px;
  white-space: nowrap;
}

/* ---------- weekday row ---------- */

.weekday-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  padding: 12px 16px 4px;
  max-width: 1100px;
  margin: 0 auto;
  width: 100%;
}
.weekday-row span {
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 11px;
  color: var(--text-secondary);
  text-align: center;
  padding: 4px 0;
}

/* ---------- grid ---------- */

.grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  padding: 0 16px 16px;
  max-width: 1100px;
  margin: 0 auto;
  width: 100%;
}

.cell {
  background: var(--bg-cell);
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 8px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 52px;
  text-align: left;
  color: var(--text-muted);
  transition: background-color 120ms ease, transform 120ms ease;
}
.cell:hover {
  background: var(--bg-cell-hover);
}
.cell:active {
  transform: scale(0.98);
}

.cell .day-num {
  font-size: 14px;
  font-weight: 500;
}
.cell .hours {
  font-size: 12px;
  color: var(--text-secondary);
  text-align: right;
  font-weight: 500;
}

.cell.logged {
  background: linear-gradient(var(--accent-tint), var(--accent-tint)), var(--bg-cell);
  border-color: var(--accent-border);
  color: var(--text-primary);
}
.cell.logged .hours {
  color: var(--success);
}

.cell.today {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.cell.out-of-month {
  opacity: 0.3;
  pointer-events: none;
}

@media (min-width: 641px) {
  .cell {
    min-height: 80px;
    padding: 10px;
  }
  .cell .day-num {
    font-size: 16px;
  }
  .cell .hours {
    font-size: 14px;
  }
}

@media (min-width: 1025px) {
  .cell {
    min-height: 110px;
    padding: 12px;
  }
}

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

.sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.6);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fade-in 150ms ease;
}

.sheet {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  width: 100%;
  max-width: 480px;
  border-radius: 16px 16px 0 0;
  display: flex;
  flex-direction: column;
  max-height: 90dvh;
  animation: slide-up 200ms ease;
  padding-bottom: env(safe-area-inset-bottom);
}

@media (min-width: 641px) {
  .sheet-overlay {
    align-items: center;
  }
  .sheet {
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-modal);
    animation: fade-in 150ms ease;
  }
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.sheet-head h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.sheet-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  overflow-y: auto;
}

.sheet-foot {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}
.sheet-foot .spacer {
  flex: 1;
}

/* ---------- form fields ---------- */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field > span {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
}

.field select,
.field textarea {
  background: var(--bg-cell);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 16px;
  font-family: inherit;
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
}

.field select {
  height: 44px;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-secondary) 50%),
    linear-gradient(135deg, var(--text-secondary) 50%, transparent 50%);
  background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
  padding-right: 32px;
}

.field textarea {
  resize: vertical;
  min-height: 72px;
  line-height: 1.4;
}

.time-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 380px) {
  .time-row {
    grid-template-columns: 1fr;
  }
}

/* ---------- chips ---------- */

.chips {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.chip {
  background: var(--bg-cell);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: var(--radius);
  padding: 0 8px;
  height: 44px;
  font-size: 14px;
  font-weight: 500;
  transition: background-color 120ms, color 120ms, border-color 120ms;
}
.chip:hover {
  color: var(--text-primary);
  background: var(--bg-cell-hover);
}
.chip[aria-checked="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ---------- total readout ---------- */

.total {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-cell);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.total strong {
  font-size: 24px;
  font-weight: 600;
}

/* ---------- animations ---------- */

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes slide-up {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0ms !important;
    transition-duration: 0ms !important;
  }
}
