:root {
  --bg: #f6f7f9; --card: #ffffff; --ink: #14171c; --muted: #5b6472; --line: #dfe3ea;
  --accent: #1f5fd1; --on-accent: #ffffff; --danger: #b42318; --ok: #157a3d; --field: #ffffff;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1216; --card: #181c22; --ink: #eef1f5; --muted: #9aa4b2; --line: #2a313b; --accent: #6ea0ff; --on-accent: #0b1220; --danger: #ff8a7a; --ok: #5fd08a; --field: #11151a; }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
[hidden] { display: none !important; }
.wrap { max-width: 920px; margin: 0 auto; padding: 24px 16px 80px; }
.loading { text-align: center; color: var(--muted); padding: 80px 0; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 24px; flex-wrap: wrap; }
.brand { font-weight: 800; font-size: 20px; letter-spacing: -0.01em; }
.brand small { font-weight: 500; color: var(--muted); font-size: 13px; margin-left: 8px; }
h1 { font-size: 26px; line-height: 1.2; margin: 0 0 4px; }
h2 { font-size: 18px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 0 0 6px; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); font-size: 14px; }
a { color: var(--accent); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 20px; margin-bottom: 16px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.row.between { justify-content: space-between; }
.grow { flex: 1 1 200px; min-width: 0; }

button, .button { font: inherit; font-weight: 600; font-size: 15px; padding: 9px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--ink); cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
button:hover, .button:hover { border-color: var(--accent); }
button:focus-visible, .button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button.primary { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
button.danger { color: var(--danger); }
button.small { padding: 5px 10px; font-size: 13px; }
button:disabled { opacity: 0.55; cursor: default; }
button.link { border: 0; background: none; padding: 0; color: var(--accent); font-weight: 600; }

label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 4px; }
label .hint { font-weight: 400; color: var(--muted); }
input[type=text], input[type=password], input[type=url], input[type=date], input[type=time], input[type=number], select, textarea {
  width: 100%; font: inherit; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--field); color: var(--ink);
}
input[type=color] { width: 48px; height: 40px; padding: 2px; border: 1px solid var(--line); border-radius: 8px; background: var(--field); }
textarea { min-height: 96px; resize: vertical; }
.field { margin-bottom: 14px; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 14px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; }
.check input { width: 18px; height: 18px; }
.error { color: var(--danger); font-size: 14px; font-weight: 600; margin: 0 0 12px; }
.invalid { border-color: var(--danger) !important; }

.login { max-width: 380px; margin: 12vh auto 0; }

.cal-list { display: grid; gap: 12px; }
.cal-item { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; background: var(--card); border: 1px solid var(--line); border-left: 5px solid var(--accent); border-radius: 12px; padding: 16px 18px; cursor: pointer; text-align: left; width: 100%; font-weight: 400; }
.cal-item .name { font-weight: 700; font-size: 17px; }
.cal-item .meta { color: var(--muted); font-size: 14px; }
.empty { text-align: center; padding: 48px 16px; color: var(--muted); }

table { width: 100%; border-collapse: collapse; font-size: 15px; }
th { text-align: left; font-size: 13px; color: var(--muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--line); }
td { padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.actions { white-space: nowrap; text-align: right; }
.ev-title { font-weight: 600; }
.table-wrap { overflow-x: auto; }

.share { display: grid; gap: 14px; }
.copybox { display: flex; gap: 8px; align-items: stretch; }
.copybox input, .copybox textarea { font: 13px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: var(--bg); }
.copybox textarea { min-height: 76px; }
.copybox button { flex: none; align-self: flex-start; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.stat b { display: block; font-size: 26px; line-height: 1.1; }
.stat span { color: var(--muted); font-size: 13px; }

dialog { border: 1px solid var(--line); border-radius: 14px; padding: 0; background: var(--card); color: var(--ink); width: min(640px, calc(100vw - 24px)); max-height: calc(100vh - 24px); }
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
dialog form { padding: 20px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; flex-wrap: wrap; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-weight: 600; font-size: 14px; z-index: 50; max-width: calc(100vw - 32px); }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 50%; vertical-align: middle; margin-right: 6px; }
.warn { background: color-mix(in srgb, var(--danger) 10%, transparent); border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent); border-radius: 8px; padding: 10px 12px; font-size: 14px; margin-bottom: 12px; }

/* Phones: stack each event's buttons under its title, and make every button a comfortable tap. */
@media (max-width: 600px) {
  .events-table, .events-table tbody, .events-table tr, .events-table td { display: block; width: 100%; }
  .events-table tr { padding: 10px 0; border-bottom: 1px solid var(--line); }
  .events-table tr:last-child { border-bottom: 0; }
  .events-table td { padding: 2px 0; border-bottom: 0; }
  .events-table td.actions { text-align: left; white-space: normal; padding-top: 8px; }
  .events-table td:empty { display: none; }
  button.small, .button.small { min-height: 40px; padding: 8px 12px; }
}
dialog form { overflow-wrap: anywhere; }
.ev-title, .cal-item .name, h1 { overflow-wrap: anywhere; }
