:root {
  --bg: #f6f5f2; --surface: #fff; --ink: #141414; --ink-2: #4a4a4a; --muted: #7a7672; --line: #e6e3de;
  --accent: #111; --accent-ink: #fff; --danger: #b3261e; --ok: #1d7a46; --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: Georgia, "Times New Roman", serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
a { color: inherit; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
h1 { font-family: var(--serif); font-weight: 600; font-size: 1.9rem; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; font-weight: 600; }
h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-top: 1.5em; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1.5rem 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.pre { white-space: pre-wrap; }
.inline { display: inline; }
[hidden] { display: none !important; }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 1rem; padding: .7rem 1.5rem; background: rgba(255,255,255,.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: .55rem; text-decoration: none; font-size: 1.1rem; letter-spacing: -.01em; }
.brand b { font-weight: 700; }
.brand-mark { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); font-family: var(--serif); font-weight: 700; }
.brand-mark.lg { width: 56px; height: 56px; font-size: 1.8rem; border-radius: 14px; }
.nav { margin-left: auto; display: flex; align-items: center; gap: .25rem; }
.nav a, .link-btn { text-decoration: none; padding: .45rem .75rem; border-radius: 8px; color: var(--ink-2); font: inherit; background: none; border: 0; cursor: pointer; }
.nav a:hover, .nav .link-btn:hover { background: #f1efeb; color: var(--ink); }
.nav a.active { background: var(--ink); color: #fff; }
.link-btn { padding: 0; color: var(--ink-2); text-decoration: underline; }
.nav .link-btn { text-decoration: none; padding: .45rem .75rem; }
.nav-toggle { display: none; margin-left: auto; background: none; border: 1px solid var(--line); border-radius: 8px; font-size: 1.2rem; padding: .2rem .6rem; cursor: pointer; }

.container { max-width: 1280px; margin: 0 auto; padding: 1.75rem 1.5rem 4rem; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.page-head p { margin: 0; }
.back { display: inline-block; text-decoration: none; color: var(--muted); font-size: .9rem; margin-bottom: .35rem; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem 1.4rem; box-shadow: var(--shadow); margin-bottom: 1.25rem; }
.card.narrow { max-width: 620px; }
.card.narrow.center { margin: 4rem auto; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
.grid-2 .card { margin: 0; }
.span-2 { grid-column: span 2; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; padding: .55rem 1rem; border-radius: 9px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; font-weight: 500; text-decoration: none; cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s; }
.btn:hover { border-color: #cfcac3; background: #faf9f7; }
.btn:disabled { opacity: .6; cursor: wait; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-primary:hover { background: #333; border-color: #333; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: #f1efeb; border-color: transparent; }
.btn-danger { background: transparent; color: var(--danger); border-color: #efc9c5; }
.btn-danger:hover { background: #fbeeec; border-color: var(--danger); }
.btn-sm { padding: .3rem .65rem; font-size: .85rem; }
.btn-block { width: 100%; }

/* Forms */
.form { display: flex; flex-direction: column; gap: .9rem; }
.form label { display: flex; flex-direction: column; gap: .3rem; font-weight: 500; font-size: .9rem; }
.form label.check { flex-direction: row; align-items: center; gap: .5rem; }
input, select, textarea { font: inherit; padding: .55rem .7rem; border: 1px solid #d8d4ce; border-radius: 8px; background: #fff; color: var(--ink); width: 100%; font-weight: 400; }
input[type=checkbox] { width: auto; accent-color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--ink); outline-offset: -1px; border-color: var(--ink); }
.row { display: flex; gap: .75rem; flex-wrap: wrap; }
.row > label { flex: 1 1 140px; }
.row > label.grow { flex: 3 1 220px; }
.form > .btn { align-self: flex-start; }
.form > .btn-block { align-self: stretch; }
.form-actions { display: flex; gap: .5rem; align-items: center; margin-top: .4rem; }
.form-actions .spacer { flex: 1; }
.copy-row { display: flex; gap: .5rem; flex-wrap: wrap; }
.copy-row input { flex: 1 1 260px; font-family: ui-monospace, monospace; font-size: .85rem; }
.search { display: flex; gap: .5rem; max-width: 460px; margin-bottom: 1rem; }

/* Alerts & badges */
.alert { padding: .7rem 1rem; border-radius: 9px; margin-bottom: 1rem; border: 1px solid; }
.alert-success { background: #edf7f0; border-color: #bfe2cb; color: #14532d; }
.alert-error { background: #fbeeec; border-color: #efc9c5; color: #7f1d1d; }
.badge { display: inline-block; padding: .15rem .55rem; border-radius: 99px; font-size: .75rem; font-weight: 600; }
.badge-dark { background: var(--ink); color: #fff; }
.badge-ok { background: #e6f4ea; color: var(--ok); }
.badge-off { background: #f1efeb; color: var(--muted); }
.chip { display: inline-block; padding: .2rem .65rem; border-radius: 99px; color: #fff; font-size: .78rem; font-weight: 600; margin-bottom: .6rem; }

/* Tables */
.table-card { padding: 0; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: .75rem 1rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; background: #fbfaf8; }
.table tr:last-child td { border-bottom: 0; }
.table tr.inactive td { color: var(--muted); }
.table a { text-decoration: none; }
.table a:hover { text-decoration: underline; }
.row-actions { text-align: right; white-space: nowrap; }
.row-actions > * { margin-left: .25rem; }

/* Definition lists */
.dl { display: grid; grid-template-columns: max-content 1fr; gap: .45rem 1.25rem; margin: 1rem 0 0; }
.dl dt { color: var(--muted); font-size: .85rem; padding-top: .1rem; }
.dl dd { margin: 0; }
.dl.compact { grid-template-columns: 1fr; gap: .1rem; }
.dl.compact dd { margin-bottom: .5rem; overflow-wrap: anywhere; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.25rem; margin-bottom: 1.25rem; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.4rem; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.stat-n { font-family: var(--serif); font-size: 2.2rem; font-weight: 600; }
.stat-l { color: var(--muted); font-size: .85rem; }

/* Day agenda */
.day-list { display: flex; flex-direction: column; gap: 1.1rem; }
.day-label { font-size: .8rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 600; margin-bottom: .4rem; }
.day-label::first-letter { text-transform: uppercase; }
.day-label.is-today { color: var(--ink); }
.event-row { display: grid; grid-template-columns: 150px 1fr; grid-template-areas: "time title" "time meta"; gap: 0 1rem; width: 100%; text-align: left; padding: .65rem .9rem; margin-bottom: .4rem; border: 1px solid var(--line); border-left: 4px solid var(--c, #888); border-radius: 8px; background: #fff; font: inherit; color: inherit; cursor: pointer; text-decoration: none; transition: background .15s; }
.event-row:hover { background: #faf9f7; }
.event-time { grid-area: time; font-weight: 600; font-variant-numeric: tabular-nums; font-size: .9rem; }
.event-title { grid-area: title; }
.event-meta { grid-area: meta; color: var(--muted); font-size: .85rem; }

/* Calendar layout */
.cal-layout { padding-bottom: 4rem; display: grid; grid-template-columns: 250px 1fr; gap: 1.25rem; align-items: start; }
.side { position: sticky; top: 76px; max-height: calc(100vh - 96px); overflow: auto; }
.actor-filter { list-style: none; padding: 0; margin: .5rem 0 0; }
.actor-filter label { display: flex; gap: .5rem; align-items: center; padding: .2rem 0; cursor: pointer; font-size: .92rem; }
.filter-search { margin-top: .5rem; padding: .4rem .6rem; font-size: .9rem; }
.legend { list-style: none; padding: 0; margin: .75rem 0 0; display: flex; flex-wrap: wrap; gap: .35rem 1rem; font-size: .82rem; color: var(--ink-2); }
.side .legend { flex-direction: column; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: .4rem; vertical-align: middle; }

/* FullCalendar theming */
.fc { --fc-border-color: var(--line); --fc-today-bg-color: #fbf6e9; --fc-button-bg-color: #fff; --fc-button-text-color: var(--ink); --fc-button-border-color: var(--line); --fc-button-hover-bg-color: #f4f2ee; --fc-button-hover-border-color: #d8d4ce; --fc-button-active-bg-color: var(--ink); --fc-button-active-border-color: var(--ink); --fc-event-border-color: transparent; --fc-list-event-hover-bg-color: #faf9f7; --fc-neutral-bg-color: #fbfaf8; }
.fc .fc-button { font-weight: 500; text-transform: none; box-shadow: none !important; padding: .4rem .8rem; }
.fc .fc-button-primary:not(:disabled).fc-button-active { color: #fff; }
.fc .fc-toolbar-title { font-family: var(--serif); font-size: 1.4rem; }
.fc .fc-toolbar-title::first-letter, .fc .fc-list-day-text::first-letter, .fc .fc-list-day-side-text::first-letter { text-transform: uppercase; }
.fc .fc-list-day-text, .fc .fc-list-day-side-text { display: inline-block; }
.fc .fc-col-header-cell-cushion, .fc .fc-daygrid-day-number { text-decoration: none; color: var(--ink-2); text-transform: capitalize; }
.fc .fc-daygrid-event { border-radius: 5px; padding: 1px 3px; font-size: .82rem; }
.fc .fc-daygrid-dot-event .fc-event-title { font-weight: 500; }
.fc-event { cursor: pointer; }

/* Actor picker */
.actor-picker { border: 1px solid #d8d4ce; border-radius: 8px; padding: .5rem .8rem .7rem; margin: 0; }
.actor-picker legend { font-weight: 500; font-size: .9rem; padding: 0 .3rem; }
.actor-picker input[type=search] { margin: .2rem 0 .5rem; padding: .4rem .6rem; }
.picker-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: .15rem 1rem; max-height: 150px; overflow: auto; }
.form .picker-list label { flex-direction: row; align-items: center; gap: .45rem; font-weight: 400; cursor: pointer; }

/* Day picking (backoffice) */
.fc .fc-daygrid-day, .fc .fc-timegrid-col { cursor: pointer; }
.fc .fc-daygrid-day.is-picked, .fc .fc-timegrid-col.is-picked { background: #e7efff; box-shadow: inset 0 0 0 2px #3b6fd8; }
.fc .fc-col-header-cell.is-picked { background: #e7efff; }
.pick-bar { position: fixed; left: 50%; bottom: 1.25rem; transform: translateX(-50%); z-index: 30; display: flex; align-items: center; gap: 1rem; width: min(760px, calc(100vw - 1.5rem)); padding: .7rem .8rem .7rem 1.2rem; background: #fff; border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 10px 40px rgba(0,0,0,.18); }
.pick-info { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick-actions { display: flex; gap: .4rem; }
.title-preview { margin: -.4rem 0 .2rem; }
.title-preview strong { color: var(--ink); }
.field-label { display: block; font-weight: 500; font-size: .9rem; margin-bottom: .35rem; }
.day-chips { display: flex; flex-wrap: wrap; gap: .35rem; margin-bottom: .5rem; }
.day-chip { display: inline-flex; align-items: center; gap: .25rem; padding: .2rem .3rem .2rem .7rem; border-radius: 99px; background: #e7efff; color: #1d3f8a; font-size: .85rem; font-weight: 500; }
.day-chip button { border: 0; background: none; cursor: pointer; font-size: 1rem; line-height: 1; color: inherit; padding: 0 .3rem; border-radius: 99px; }
.day-chip button:hover { background: rgba(0,0,0,.08); }
.add-day { display: flex; gap: .5rem; max-width: 320px; }
.form .hint { margin: -.5rem 0 0; }

/* Modal */
dialog.modal { border: 0; border-radius: 16px; padding: 0; width: min(640px, calc(100vw - 2rem)); max-height: calc(100vh - 2rem); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog.modal::backdrop { background: rgba(20,20,20,.45); }
.modal-body { position: relative; padding: 1.5rem 1.6rem; }
.modal-body h2 { font-family: var(--serif); font-size: 1.5rem; padding-right: 2rem; }
.modal-close { position: absolute; top: .8rem; right: .9rem; border: 0; background: none; font-size: 1.6rem; line-height: 1; cursor: pointer; color: var(--muted); }

/* Login */
.login-page { background: radial-gradient(1200px 600px at 20% 0%, #fff 0%, var(--bg) 60%); }
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }
.login-card { width: min(400px, 100%); background: #fff; border: 1px solid var(--line); border-radius: 18px; padding: 2.25rem 2rem; box-shadow: 0 10px 40px rgba(0,0,0,.06); }
.login-brand { text-align: center; margin-bottom: 1.5rem; }
.login-brand h1 { font-family: var(--font); font-weight: 400; font-size: 1.7rem; margin: .8rem 0 .2rem; }
.login-brand h1 b { font-weight: 700; }

@media (max-width: 900px) {
  .cal-layout { grid-template-columns: 1fr; }
  .side { position: static; max-height: none; }
  .side .legend { flex-direction: row; }
  .actor-filter { display: flex; flex-wrap: wrap; gap: 0 1rem; max-height: 160px; overflow: auto; }
}
@media (max-width: 720px) {
  body { font-size: 15px; }
  .container { padding: 1rem .8rem 3rem; }
  .topbar { padding: .6rem 1rem; flex-wrap: wrap; }
  .nav-toggle { display: block; }
  .nav { display: none; width: 100%; flex-direction: column; align-items: stretch; margin: .4rem 0 0; }
  .nav.open { display: flex; }
  .nav form button { width: 100%; text-align: left; }
  .topbar .badge { display: none; }
  h1 { font-size: 1.5rem; }
  .card { padding: 1rem; }
  .grid-2, .stats { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .event-row { grid-template-columns: 1fr; grid-template-areas: "time" "title" "meta"; }
  .hide-sm { display: none; }
  .fc .fc-toolbar-title { font-size: 1.1rem; }
  .fc .fc-toolbar { gap: .4rem; }
  .row-actions { white-space: normal; }
  .pick-bar { flex-wrap: wrap; bottom: .6rem; }
  .pick-info { white-space: normal; flex-basis: 100%; }
}
