:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-2: #273449;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --border: #334155;
  --primary: #3b82f6;
  --danger: #ef4444;
  --success: #10b981;
  --today: #f59e0b;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px;
  -webkit-text-size-adjust: 100%;
}

.topbar {
  display: flex; align-items: center; gap: 1rem; padding: .6rem 1rem;
  background: var(--panel); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20; padding-top: max(.6rem, env(safe-area-inset-top));
}
.brand { font-weight: 700; }
.nav { display: flex; gap: .75rem; }
.nav a { color: var(--text); text-decoration: none; padding: .3rem .6rem; border-radius: 6px; }
.nav a:hover { background: var(--panel-2); }
.user { margin-left: auto; display: flex; align-items: center; gap: .5rem; color: var(--muted); }
.inline { display: inline; }
.link-btn { background: none; border: none; color: var(--primary); cursor: pointer; font: inherit; }

.content { padding: 1rem; max-width: 1400px; margin: 0 auto; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 1rem; margin-bottom: 1rem; }

.btn { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: .45rem .8rem; cursor: pointer; font: inherit; }
.btn:hover { border-color: var(--primary); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.small { padding: .25rem .5rem; font-size: .85rem; }

.alert { padding: .6rem .9rem; border-radius: 8px; margin-bottom: 1rem; }
.alert.success { background: rgba(16,185,129,.15); border: 1px solid var(--success); }
.alert.error { background: rgba(239,68,68,.15); border: 1px solid var(--danger); }

/* Login */
.login-wrap { display: flex; justify-content: center; padding-top: 8vh; }
.login-card { width: min(360px, 92vw); display: flex; flex-direction: column; gap: .75rem; }
.login-card h1 { text-align: center; margin: 0 0 .5rem; }
.login-logo { width: 96px; height: 96px; object-fit: contain; border-radius: 20px; align-self: center; box-shadow: 0 4px 14px rgba(0,0,0,.35); }
label { display: flex; flex-direction: column; gap: .25rem; font-size: .85rem; color: var(--muted); }
label.checkbox { flex-direction: row; align-items: center; gap: .4rem; }
input, select, textarea { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: .5rem; font: inherit; }
input[type=color] { padding: .1rem; height: 2.2rem; }
.hint { color: var(--muted); font-size: .8rem; text-align: center; }

/* Month */
.calendar-page { display: grid; gap: 1rem; }
.month-toolbar { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: .75rem; }
.month-toolbar .day-panel-actions { margin-left: auto; display: flex; gap: .5rem; }
.nav-group { display: flex; gap: .5rem; }
.weekday-header, .month-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.weekday-header { color: var(--muted); font-size: .8rem; margin-bottom: 4px; text-align: center; }
.day-cell { background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; min-height: 96px; padding: 4px; cursor: pointer; overflow: hidden; }
.day-cell.other-month { opacity: .45; }
.day-cell.today { outline: 2px solid var(--today); }
.day-cell.selected { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary) inset; }
.day-num { font-size: .8rem; font-weight: 600; margin-bottom: 2px; }
.day-events { display: flex; flex-direction: column; gap: 2px; }
.event-chip { font-size: .72rem; padding: 1px 4px; background: rgba(255,255,255,.06); border-left: 3px solid var(--primary); border-radius: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.event-chip.done { text-decoration: line-through; opacity: .6; }
.more { font-size: .7rem; color: var(--muted); }

/* Day panel */
.day-panel-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: .5rem; }
.day-panel-actions { display: flex; gap: .5rem; }
.day-panel-lists { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-top: .75rem; }
.panel-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .4rem; }
.panel-list li { background: var(--panel-2); border-left: 3px solid var(--primary); border-radius: 6px; padding: .55rem .6rem; cursor: pointer; display: flex; flex-direction: row; align-items: center; gap: .6rem; }
.panel-list li.empty { color: var(--muted); border-left-color: transparent; cursor: default; font-size: 1rem; }
.panel-list.completed li { opacity: .65; text-decoration: line-through; }
.ev-title { font-weight: 600; font-size: 1.5rem; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.task-check { flex: 0 0 auto; width: 28px; height: 28px; cursor: pointer; }

/* Week */
.week-allday { display: grid; gap: 2px; border-bottom: 1px solid var(--border); padding-bottom: 4px; margin-bottom: 4px; }
.gutter-label, .hour-label { color: var(--muted); font-size: .7rem; }
.allday-cell { min-height: 24px; display: flex; flex-direction: column; gap: 2px; }
.allday-chip { font-size: .72rem; color: #fff; border-radius: 4px; padding: 1px 4px; cursor: pointer; }
.week-scroll { max-height: 70vh; overflow-y: auto; }
.week-grid { display: grid; position: relative; }
.time-gutter { display: flex; flex-direction: column; }
.hour-label { text-align: right; padding-right: 4px; border-top: 1px solid var(--border); }
.day-column { position: relative; border-left: 1px solid var(--border); }
.hour-slot { border-top: 1px solid var(--border); cursor: pointer; }
.hour-slot:hover { background: rgba(255,255,255,.03); }
.week-event { position: absolute; color: #fff; border-radius: 6px; padding: 2px 4px; font-size: .72rem; overflow: hidden; cursor: pointer; box-shadow: 0 1px 3px rgba(0,0,0,.4); }
.week-event.done { opacity: .55; text-decoration: line-through; }
.week-event strong { display: block; }
.now-line { position: absolute; left: 0; right: 0; height: 2px; background: var(--danger); z-index: 5; }
.now-line::before { content: ''; position: absolute; left: -4px; top: -3px; width: 8px; height: 8px; border-radius: 50%; background: var(--danger); }

/* Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: flex-start; justify-content: center; padding: 4vh 1rem; z-index: 50; overflow-y: auto; }
.modal-overlay[hidden] { display: none; }
.modal { width: min(540px, 96vw); }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .5rem; }
.modal-body { display: flex; flex-direction: column; gap: .6rem; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.weekday-picker { display: flex; flex-wrap: wrap; gap: .5rem; }
.weekday-picker label { flex-direction: row; align-items: center; gap: .25rem; }
.scope-picker { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; background: var(--panel-2); padding: .5rem; border-radius: 8px; }
.scope-picker label { flex-direction: row; align-items: center; gap: .3rem; }
.modal-foot { display: flex; align-items: center; gap: .5rem; margin-top: .5rem; }
.modal-foot .spacer { flex: 1; }
fieldset.recurrence { border: 1px solid var(--border); border-radius: 8px; }

/* Admin */
.admin-tabs { display: flex; gap: .5rem; margin-bottom: 1rem; }
.admin-tabs a { color: var(--text); text-decoration: none; padding: .4rem .8rem; border-radius: 8px; background: var(--panel); border: 1px solid var(--border); }
.admin-tabs a.active { background: var(--primary); border-color: var(--primary); }
.inline-form { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
table.grid { width: 100%; border-collapse: collapse; }
table.grid th, table.grid td { text-align: left; padding: .5rem; border-bottom: 1px solid var(--border); }
td.actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* Responsive */
@media (max-width: 720px) {
  .day-panel-lists { grid-template-columns: 1fr; }
  .day-cell { min-height: 64px; }
  .event-chip span { display: inline; }
  .field-row { grid-template-columns: 1fr; }
  .nav a { padding: .3rem .4rem; }
}
