/* Grand Georick Energy – Company Calendar
   Layout: a sticky brand bar, a toolbar (period + view + filters), the calendar grid, a day panel. Warm off-white
   ground with the company orange as the single accent; each employee owns a colour that marks their events. */
:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --surface-2: #faf7f2;
  --fg: #2b2a28;
  --muted: #716a62;
  --line: #e5ded4;
  --line-strong: #cdc3b6;
  --accent: #f28c28;
  --accent-ink: #b45f0a;
  --accent-soft: #fdebd9;
  --red: #c1121f;
  --red-soft: #fbe3e5;
  --gold: #ffc043;
  --today: #fff1cf;
  --weekend: #f9f6f1;
  --shadow: 0 14px 40px rgba(43, 42, 40, 0.16);
  --font-display: 'Barlow Condensed', 'Arial Narrow', 'Helvetica Neue', Arial, sans-serif;
  --font-body: 'IBM Plex Sans', system-ui, 'Segoe UI', Roboto, Arial, sans-serif;
  --radius: 10px;
  --gutter-l: max(16px, env(safe-area-inset-left, 0px));
  --gutter-r: max(16px, env(safe-area-inset-right, 0px));
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1917; --surface: #252220; --surface-2: #2c2825; --fg: #f1ece5; --muted: #a89f94; --line: #3a342e; --line-strong: #4d453c;
    --accent: #f59a3f; --accent-ink: #ffb86b; --accent-soft: #3a2a17; --red: #e5484d; --red-soft: #3b1d20; --today: #3b2f16; --weekend: #211e1b;
    --shadow: 0 14px 40px rgba(0, 0, 0, 0.55);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--fg); font-family: var(--font-body); font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased; min-height: 100vh; display: flex; flex-direction: column; }
body.modal-open { overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; text-wrap: balance; }
p { margin: 0; }
a { color: var(--accent-ink); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Top bar ---------- */
.topbar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-block: 10px; padding-left: var(--gutter-l); padding-right: var(--gutter-r); background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: inherit; min-width: 0; }
.brand-logo { height: 44px; width: auto; max-width: 100%; display: block; }
.brand-text { display: flex; flex-direction: column; line-height: 1.05; min-width: 0; }
.brand-name { font-family: var(--font-display); font-weight: 700; font-size: 22px; letter-spacing: 0.01em; text-transform: uppercase; white-space: nowrap; }
.brand-sub { font-size: 12px; color: var(--muted); letter-spacing: 0.12em; text-transform: uppercase; }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.me-pill { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--surface-2); border-radius: 999px; padding: 6px 12px 6px 8px; font-size: 13px; max-width: 180px; }
.me-pill .me-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 0 14px; border-radius: 8px; border: 1px solid transparent; font-weight: 500; white-space: nowrap; }
.btn-primary { background: var(--accent); color: #1f1710; border-color: var(--accent); font-weight: 600; }
.btn-primary:hover { filter: brightness(1.05); }
.btn-primary .plus { font-size: 20px; line-height: 1; font-weight: 500; margin-top: -2px; }
.btn-ghost { background: var(--surface); border-color: var(--line-strong); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--red); color: #fff; border-color: var(--red); font-weight: 600; }
.btn-danger-text { color: var(--red); }
.btn-icon { width: 40px; padding: 0; font-size: 24px; line-height: 1; background: var(--surface); border-color: var(--line-strong); }
.btn-sm { min-height: 34px; padding: 0 10px; font-size: 13px; }
.btn[disabled] { opacity: 0.55; cursor: progress; }
.link { background: none; border: 0; padding: 0; color: var(--accent-ink); text-decoration: underline; text-underline-offset: 2px; }

/* ---------- Main ---------- */
.app { flex: 1; width: 100%; max-width: 1320px; margin: 0 auto; padding-block: 16px 24px; padding-left: var(--gutter-l); padding-right: var(--gutter-r); display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.nav { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.nav-arrows { display: flex; gap: 4px; }
.period-title { font-family: var(--font-display); font-weight: 700; font-size: 34px; line-height: 1; letter-spacing: 0.005em; text-transform: uppercase; }
.period-title small { font-size: 0.55em; color: var(--muted); font-weight: 600; margin-left: 8px; letter-spacing: 0.04em; }
.controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.segmented { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; background: var(--surface); }
.segmented button { border: 0; background: transparent; padding: 0 14px; min-height: 38px; font-weight: 500; color: var(--muted); }
.segmented button + button { border-left: 1px solid var(--line); }
.segmented button.active { background: var(--fg); color: var(--bg); }
.select-wrap select { min-height: 40px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); padding: 0 12px; max-width: 200px; }

.legend { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.legend-chip { display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 4px 12px 4px 8px; font-size: 13px; color: var(--muted); }
.legend-chip.active { border-color: var(--fg); color: var(--fg); background: var(--surface-2); }
.legend-chip .dot { width: 10px; height: 10px; }
.legend-label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); margin-right: 4px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--c, var(--accent)); flex-shrink: 0; vertical-align: middle; }

/* ---------- Month grid ---------- */
.calendar { min-width: 0; }
.grid-head { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 1px; padding: 0 1px; margin-bottom: 4px; }
.grid-head span { font-size: 12px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); padding: 4px 8px; }
.grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.day { background: var(--surface); min-height: 118px; padding: 6px; display: flex; flex-direction: column; gap: 4px; min-width: 0; cursor: pointer; position: relative; text-align: left; border: 0; }
.day:hover { background: var(--surface-2); }
.day.weekend { background: var(--weekend); }
.day.other { color: var(--muted); }
.day.other .day-num { opacity: 0.45; }
.day.today .day-num { background: var(--accent); color: #1f1710; }
.day.selected { box-shadow: inset 0 0 0 2px var(--accent); }
.day-num { font-family: var(--font-display); font-weight: 600; font-size: 18px; line-height: 1; width: 28px; height: 28px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-variant-numeric: tabular-nums; }
.day-events { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.chip { display: block; width: 100%; text-align: left; border: 0; border-left: 3px solid var(--c); border-radius: 4px; padding: 2px 6px; font-size: 12px; line-height: 1.35; color: var(--fg); background: color-mix(in srgb, var(--c) 16%, var(--surface)); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip:hover { background: color-mix(in srgb, var(--c) 28%, var(--surface)); }
.chip .t { color: var(--muted); font-variant-numeric: tabular-nums; margin-right: 4px; }
.chip.cont { border-left-style: dotted; }
.more { border: 0; background: none; color: var(--accent-ink); font-size: 12px; text-align: left; padding: 0 6px; font-weight: 500; }
.dots { display: none; gap: 3px; flex-wrap: wrap; }
.dots .dot { width: 7px; height: 7px; }
.dots .n { font-size: 10px; color: var(--muted); line-height: 1; }

/* ---------- Week view ---------- */
.week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.wday { background: var(--surface); min-height: 240px; padding: 8px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.wday.weekend { background: var(--weekend); }
.wday-head { display: flex; align-items: baseline; gap: 6px; }
.wday-head .n { font-family: var(--font-display); font-weight: 700; font-size: 26px; line-height: 1; width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; }
.wday.today .wday-head .n { background: var(--accent); color: #1f1710; }
.wday-head .d { font-size: 12px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); }
.wday .add-here { margin-top: auto; align-self: flex-start; }

/* ---------- Event rows (week, list, day panel) ---------- */
.ev { display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: 10px; width: 100%; text-align: left; border: 0; border-left: 4px solid var(--c); border-radius: 6px; padding: 8px 10px; background: color-mix(in srgb, var(--c) 10%, var(--surface)); color: var(--fg); align-items: start; }
.ev:hover { background: color-mix(in srgb, var(--c) 20%, var(--surface)); }
.ev-time { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; padding-top: 2px; line-height: 1.3; }
.ev-main { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.ev-title { font-weight: 600; overflow-wrap: anywhere; }
.ev-meta { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.ev-meta .who { color: var(--fg); }
.wday .ev { grid-template-columns: 1fr; gap: 2px; }
.wday .ev-time { padding-top: 0; }

.list { display: flex; flex-direction: column; gap: 18px; }
.list-day { display: grid; grid-template-columns: 160px minmax(0, 1fr); gap: 14px; align-items: start; }
.list-day-head { position: sticky; top: 80px; }
.list-day-head .d { font-family: var(--font-display); font-weight: 700; font-size: 24px; line-height: 1; text-transform: uppercase; }
.list-day-head .y { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.1em; margin-top: 4px; }
.list-day-head .today-tag { display: inline-block; margin-top: 6px; background: var(--accent); color: #1f1710; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; padding: 2px 8px; border-radius: 999px; }
.list-events { display: flex; flex-direction: column; gap: 6px; min-width: 0; }

.day-panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.day-panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.day-panel-head h2 { font-family: var(--font-display); font-weight: 700; font-size: 24px; line-height: 1; text-transform: uppercase; }
.day-panel-head h2 small { font-size: 0.6em; color: var(--muted); margin-left: 6px; letter-spacing: 0.04em; }

.empty { border: 1px dashed var(--line-strong); border-radius: var(--radius); padding: 28px 18px; text-align: center; color: var(--muted); display: flex; flex-direction: column; gap: 10px; align-items: center; }
.empty strong { color: var(--fg); font-family: var(--font-display); font-size: 20px; font-weight: 600; text-transform: uppercase; }

/* ---------- Setup ---------- */
.setup { display: flex; justify-content: center; padding: 24px 0; }
.setup-card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 28px; max-width: 520px; width: 100%; display: flex; flex-direction: column; gap: 14px; box-shadow: var(--shadow); }
.setup-card h2 { font-family: var(--font-display); font-size: 32px; font-weight: 700; line-height: 1; text-transform: uppercase; }
.setup-card .lead { color: var(--muted); }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); font-weight: 500; }
.field input, .field select, .field textarea { min-height: 44px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface-2); padding: 8px 12px; width: 100%; }
.field textarea { resize: vertical; min-height: 72px; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.hint { font-size: 13px; color: var(--muted); }
.form-error { background: var(--red-soft); color: var(--red); border-radius: 8px; padding: 10px 12px; font-size: 14px; font-weight: 500; }
.ok-box { background: var(--accent-soft); border-radius: 8px; padding: 12px 14px; font-size: 14px; display: flex; flex-direction: column; gap: 6px; }
.ok-box code { font-size: 22px; font-family: var(--font-display); font-weight: 700; letter-spacing: 0.08em; }
.code-box { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.code-row { display: flex; gap: 8px; }
.code-row input { flex: 1; letter-spacing: 0.08em; text-transform: uppercase; }
.identity-box { display: flex; align-items: center; gap: 12px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.identity-box .dot { width: 14px; height: 14px; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch { width: 30px; height: 30px; border-radius: 50%; border: 3px solid transparent; background: var(--c); padding: 0; }
.swatch.active { border-color: var(--fg); box-shadow: 0 0 0 2px var(--surface); }

/* ---------- Modal ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(22, 17, 12, 0.6); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.modal { background: var(--surface); border-radius: 14px; width: 100%; max-width: 560px; max-height: calc(100% - 32px); overflow: auto; box-shadow: var(--shadow); }
.modal-wide { max-width: 860px; }
.modal-body { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.modal-title { font-family: var(--font-display); font-weight: 700; font-size: 28px; line-height: 1; text-transform: uppercase; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.modal-actions .spacer { flex: 1; }
.event-title { font-family: var(--font-display); font-weight: 700; font-size: 30px; line-height: 1.05; overflow-wrap: anywhere; }
.tag { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 600; padding: 4px 10px; border-radius: 999px; background: color-mix(in srgb, var(--c) 16%, var(--surface)); }
.tag::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.detail { margin: 0; display: grid; grid-template-columns: 90px minmax(0, 1fr); gap: 8px 12px; }
.detail div { display: contents; }
.detail dt { font-size: 12px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); padding-top: 3px; }
.detail dd { margin: 0; overflow-wrap: anywhere; }
.detail dd.pre { white-space: pre-wrap; }
.danger-box { border: 1px solid var(--red); border-radius: 10px; padding: 14px; display: flex; flex-direction: column; gap: 10px; }

/* ---------- Admin ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); font-weight: 600; background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
td .sub { display: block; font-size: 12px; color: var(--muted); }
.badge { display: inline-block; font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); }
.badge.admin { background: var(--accent-soft); border-color: transparent; color: var(--accent-ink); }
.badge.off { color: var(--muted); }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.editor { background: var(--surface-2); border-radius: 10px; padding: 14px; display: flex; flex-direction: column; gap: 12px; }
details summary { cursor: pointer; color: var(--muted); font-size: 14px; }
.audit-time { white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; }

/* ---------- Footer & toast ---------- */
.foot { padding-block: 16px; padding-left: var(--gutter-l); padding-right: var(--gutter-r); border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; }
.foot .sep { margin: 0 8px; }
.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 12px 18px; border-radius: 10px; font-weight: 500; box-shadow: var(--shadow); z-index: 60; max-width: calc(100% - 32px); }
.toast.error { background: var(--red); color: #fff; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .period-title { font-size: 28px; }
  .list-day { grid-template-columns: 1fr; gap: 8px; }
  .list-day-head { position: static; display: flex; align-items: baseline; gap: 10px; }
  .list-day-head .y { margin-top: 0; }
  .week { grid-template-columns: 1fr; }
  .wday { min-height: 0; }
  .wday .ev { grid-template-columns: 64px minmax(0, 1fr); }
  .wday .add-here { align-self: flex-end; margin-top: 0; }
}
@media (max-width: 720px) {
  .brand-name { font-size: 18px; }
  .brand-logo { height: 36px; }
  .btn-admin-text { display: none; }
  .day { min-height: 64px; padding: 4px; gap: 3px; }
  .day-num { width: 26px; height: 26px; font-size: 16px; }
  .day-events, .more { display: none; }
  .dots { display: flex; }
  .grid-head span { padding: 4px 2px; text-align: center; font-size: 11px; }
  .day-panel-head h2 { font-size: 20px; }
  .modal-body { padding: 16px; }
  .detail { grid-template-columns: 1fr; gap: 2px 0; }
  .detail dd { margin-bottom: 8px; }
}
@media (max-width: 600px) {
  .topbar { flex-wrap: wrap; }
  .topbar-actions { width: 100%; justify-content: flex-end; }
  .me-pill { margin-right: auto; }
  .row-2 { grid-template-columns: 1fr; }
  .backdrop { align-items: flex-end; padding: 0; }
  .modal { border-radius: 16px 16px 0 0; max-height: 94%; }
  .segmented button { padding: 0 11px; }
  .toolbar .controls { width: 100%; }
  .select-wrap { flex: 1; min-width: 0; }
  .select-wrap select { width: 100%; max-width: none; }
}
@media (prefers-reduced-motion: no-preference) {
  .toast { animation: rise 0.25s ease-out; }
  @keyframes rise { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }
}
