:root {
  color-scheme: light;
  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface-raised: #ffffff;
  --surface-muted: #f7f9fb;
  --border: #dce3ea;
  --border-strong: #b8c5d2;
  --text: #17202c;
  --muted: #68778b;
  --primary: #d71920;
  --primary-dark: #a90f16;
  --red: #c93434;
  --red-soft: #fff0ef;
  --green: #18704d;
  --green-soft: #e9f7ef;
  --blue: #275fa8;
  --blue-soft: #e9f1ff;
  --amber: #966000;
  --amber-soft: #fff5db;
  --violet: #6b47b4;
  --violet-soft: #f1ecff;
  --teal: #12707a;
  --teal-soft: #e6f7f8;
  --shadow-sm: 0 1px 2px rgba(23, 32, 44, 0.06);
  --shadow-md: 0 10px 26px rgba(23, 32, 44, 0.07);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 0;
  background:
    linear-gradient(180deg, #fff 0, var(--bg) 220px),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(215, 25, 32, 0.28);
  outline-offset: 2px;
}

a {
  color: var(--blue);
  font-weight: 500;
}

a.ghost-button,
a.primary-button {
  text-decoration: none;
}

.app-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  min-height: 72px;
  display: grid;
  grid-template-columns: minmax(230px, 1fr) auto minmax(220px, 1fr);
  align-items: center;
  gap: 14px;
  padding: 12px 20px;
  background: rgba(255, 255, 255, 0.9);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar h1,
.panel h2,
.dialog-header h2,
.calendar-toolbar h2 {
  margin: 0;
  line-height: 1.1;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: 21px;
  font-weight: 500;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: uppercase;
}

.topbar-actions,
.dialog-actions,
.dialog-actions > div,
.day-status-row,
.calendar-summary,
.view-switcher {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-actions {
  justify-content: flex-end;
}

.view-switcher {
  min-height: 48px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-muted);
}

.view-button,
.primary-button,
.ghost-button,
.danger-button,
.icon-button,
.chip-button {
  min-height: 44px;
  border-radius: 7px;
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 13px;
  color: var(--text);
  background: transparent;
  transition: background-color 160ms ease, border-color 160ms ease, transform 160ms ease;
  touch-action: manipulation;
}

.view-button {
  min-height: 36px;
  color: var(--muted);
  font-weight: 500;
}

.view-button.active {
  background: var(--surface);
  color: var(--primary);
  border-color: var(--border);
  box-shadow: var(--shadow-sm);
}

.primary-button {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
  font-weight: 500;
}

.primary-button:hover {
  background: var(--primary-dark);
}

.ghost-button {
  background: var(--surface-muted);
  border-color: var(--border);
  font-weight: 500;
}

.danger-button {
  border-color: #efb5b2;
  color: var(--red);
  background: var(--red-soft);
  font-weight: 500;
}

.icon-button {
  width: 44px;
  padding: 0;
  background: var(--surface);
  border-color: var(--border);
}

.icon-button:hover,
.chip-button:hover,
.view-button:hover {
  transform: translateY(-1px);
}

.icon-button svg,
.primary-button svg,
.danger-button svg,
.ghost-button svg,
.view-button svg {
  width: 17px;
  height: 17px;
  stroke-width: 2.2;
}

.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr) 360px;
  gap: 14px;
  padding: 14px;
  align-items: start;
}

.left-rail,
.detail-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.left-rail {
  font-size: 14px;
  line-height: 1.35;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.panel.compact,
.detail-card {
  padding: 12px;
}

.detail-card {
  box-shadow: var(--shadow-md);
}

.panel-heading,
.calendar-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-heading h2 {
  font-size: 15px;
  font-weight: 500;
}

.left-rail .panel-heading {
  margin-bottom: 10px;
}

.left-rail .panel-heading h2 {
  font-size: 14px;
  font-weight: 500;
}

.calendar-toolbar {
  min-height: 54px;
  padding: 0 2px 8px;
}

.calendar-toolbar h2 {
  font-size: 20px;
  font-weight: 500;
}

.month-control {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  gap: 8px;
}

.month-control strong,
.month-control span {
  display: block;
  text-align: center;
}

.month-control strong {
  font-size: 14px;
  font-weight: 500;
}

.month-control span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.filter-list,
.warning-list,
.timeline,
.surface-stack {
  display: grid;
  gap: 8px;
}

.chip-button {
  justify-content: flex-start;
  width: 100%;
  background: var(--surface-muted);
  border-color: var(--border);
  font-size: 14px;
  font-weight: 500;
  min-height: 38px;
  padding: 0 10px;
  line-height: 1.2;
}

.chip-button.active {
  border-color: var(--surface-color, var(--border-strong));
  background: var(--surface-bg);
}

.chip-button.active:not([data-surface]) {
  background: #fff;
}

.surface-dot,
.mini-dot {
  border-radius: 999px;
  flex: 0 0 auto;
}

.surface-dot {
  width: 10px;
  height: 10px;
}

.mini-dot {
  width: 7px;
  height: 7px;
}

.count-pill,
.status-pill,
.summary-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  padding: 0 9px;
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.filter-count {
  margin-left: auto;
  min-width: 22px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: rgba(104, 119, 139, 0.12);
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
}

.all-dot {
  background: linear-gradient(135deg, var(--green), var(--amber), var(--violet));
}

.summary-pill[data-surface] {
  background: var(--surface-bg);
  color: var(--surface-color);
}

.warning-item {
  width: 100%;
  padding: 9px 10px;
  border-radius: 7px;
  border: 1px solid #edc06f;
  background: var(--amber-soft);
  color: #583800;
  font-size: 13px;
  line-height: 1.35;
  text-align: left;
}

.warning-item strong {
  display: block;
  margin-bottom: 4px;
  color: var(--amber);
  font-size: 13px;
  font-weight: 500;
}

.calendar-area {
  min-width: 0;
}

.presets-topbar {
  grid-template-columns: minmax(230px, 0.8fr) minmax(280px, 1fr) minmax(260px, 0.8fr);
}

.preset-search {
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.preset-search svg {
  width: 17px;
  height: 17px;
  color: var(--muted);
  flex: 0 0 auto;
}

.preset-search input {
  min-height: 40px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.preset-search input:focus-visible {
  outline: 0;
}

.preset-page {
  flex: 1;
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr);
  gap: 14px;
  padding: 14px;
  align-items: start;
}

.preset-sidebar,
.preset-main {
  min-width: 0;
}

.preset-sidebar {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.preset-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 10px;
}

.preset-card {
  min-width: 0;
  min-height: 176px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-left: 4px solid var(--surface-color);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: var(--shadow-sm);
}

.preset-card-main {
  display: grid;
  gap: 8px;
}

.preset-card h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 500;
  line-height: 1.3;
}

.preset-health {
  display: grid;
  gap: 8px;
}

.health-row {
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 13px;
}

.health-row strong {
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
}

.health-row.warn {
  border-color: #edc06f;
  background: var(--amber-soft);
  color: #583800;
}

.preset-dialog {
  width: min(860px, calc(100vw - 32px));
}

.calendar-weekdays,
.calendar-grid.month-view {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
}

.calendar-weekdays {
  gap: 8px;
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  text-align: center;
}

.calendar-grid {
  gap: 8px;
}

.calendar-grid.day-view {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
}

.calendar-grid.week-view {
  display: grid;
  gap: 10px;
}

.week-lane {
  display: grid;
  grid-template-columns: 132px minmax(0, 1fr);
  min-height: 124px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.week-lane-label {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 12px;
  border-right: 1px solid var(--border);
  background: var(--surface-bg);
  color: var(--surface-color);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.25;
}

.week-lane-label .filter-count {
  margin-left: auto;
  background: rgba(255, 255, 255, 0.72);
}

.week-lane-days {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
}

.week-day-cell {
  min-height: 124px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border: 0;
  border-right: 1px solid var(--border);
  background: #fff;
  text-align: left;
}

.week-day-cell:last-child {
  border-right: 0;
}

.week-day-cell.selected {
  background: #fffafa;
  box-shadow: inset 0 0 0 2px rgba(215, 25, 32, 0.22);
}

.week-day-cell.has-warning {
  background: #fffdf8;
}

.week-day-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}

.week-day-head strong {
  width: 26px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  color: var(--text);
  background: var(--surface-muted);
  font-size: 13px;
  font-weight: 500;
}

.week-day-cell.today .week-day-head strong {
  background: var(--primary);
  color: #fff;
}

.week-day-items {
  display: grid;
  align-content: start;
  gap: 6px;
}

.week-item {
  min-height: 34px;
  font-size: 12px;
  background: var(--surface-bg);
}

.week-item-title {
  white-space: normal;
}

.week-item-time {
  margin-left: auto;
  color: var(--muted);
  font-size: 11px;
}

.week-empty {
  color: #b4bfcb;
  font-size: 13px;
}

.day-cell {
  min-height: 132px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-raised);
  box-shadow: var(--shadow-sm);
  text-align: left;
  overflow: hidden;
}

.day-view .day-cell {
  min-height: 560px;
  padding: 14px;
}

.day-cell.outside {
  opacity: 0.46;
}

.day-cell.selected {
  border-color: rgba(215, 25, 32, 0.6);
  box-shadow: 0 0 0 3px rgba(215, 25, 32, 0.12), var(--shadow-md);
}

.day-cell.has-warning {
  border-color: #e4af57;
}

.day-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.day-number {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  font-weight: 500;
  background: var(--surface-muted);
}

.day-name {
  margin-left: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
}

.day-cell.today .day-number {
  background: var(--primary);
  color: #fff;
}

.day-badges {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.day-items {
  display: grid;
  align-content: start;
  gap: 6px;
  overflow: hidden;
}

.week-view .day-items,
.day-view .day-items {
  overflow: visible;
}

.calendar-item,
.surface-item,
.timeline-item {
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: 7px;
  background: #fff;
}

.calendar-item {
  min-height: 28px;
  padding: 5px 7px;
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--text);
  font-size: 12px;
  line-height: 1.25;
  box-shadow: 0 1px 0 rgba(23, 32, 44, 0.02);
}

.week-view .calendar-item,
.day-view .calendar-item {
  min-height: 38px;
  font-size: 13px;
}

.item-priority {
  min-width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  background: var(--surface-bg);
  color: var(--surface-color);
  font-size: 11px;
  font-weight: 500;
}

.calendar-item span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.week-view .calendar-item span:last-child,
.day-view .calendar-item span:last-child {
  white-space: normal;
}

.more-count {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.empty-state {
  padding: 14px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  border: 1px dashed var(--border-strong);
  border-radius: 7px;
  background: var(--surface-muted);
}

.surface-group {
  display: grid;
  gap: 8px;
}

.surface-title {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
}

.surface-item,
.timeline-item {
  padding: 10px;
}

.surface-item-header,
.timeline-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.surface-item h3,
.timeline-item h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.3;
}

.meta-line {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.surface-actions {
  margin-top: 12px;
  display: flex;
  gap: 6px;
}

.item-action-button {
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface-muted);
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.item-action-button:hover {
  color: var(--blue);
  background: #fff;
}

.item-action-button.danger:hover {
  color: var(--red);
  border-color: #efb5b2;
  background: var(--red-soft);
}

.item-action-button svg {
  width: 15px;
  height: 15px;
  stroke-width: 2;
}

.timeline-time {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.event-dialog,
.confirm-dialog {
  width: min(760px, calc(100vw - 32px));
  border: 0;
  border-radius: var(--radius);
  padding: 0;
  box-shadow: 0 28px 80px rgba(23, 32, 44, 0.28);
}

.confirm-dialog {
  width: min(420px, calc(100vw - 32px));
  padding: 18px;
}

.event-dialog::backdrop,
.confirm-dialog::backdrop {
  background: rgba(23, 32, 44, 0.48);
  backdrop-filter: blur(4px);
}

.event-dialog form {
  padding: 18px;
}

.dialog-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

label {
  display: grid;
  gap: 6px;
}

label span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.preset-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.preset-status {
  grid-column: 1 / -1;
  min-height: 18px;
  color: var(--muted);
  font-size: 12px;
}

.wide {
  grid-column: 1 / -1;
}

input,
select,
textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  padding: 9px 10px;
}

textarea {
  resize: vertical;
  line-height: 1.5;
}

.dialog-actions {
  justify-content: space-between;
  margin-top: 18px;
}

.confirm-content {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.confirm-icon {
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  color: var(--red);
  background: var(--red-soft);
}

.confirm-icon svg {
  width: 19px;
  height: 19px;
}

.confirm-content h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 500;
  letter-spacing: 0;
}

.confirm-content p:last-child {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.4;
}

.confirm-actions {
  margin-top: 18px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

[data-surface="theme"] { --surface-color: var(--teal); --surface-bg: var(--teal-soft); }
[data-surface="offer"] { --surface-color: var(--green); --surface-bg: var(--green-soft); }
[data-surface="banner"] { --surface-color: var(--amber); --surface-bg: var(--amber-soft); }
[data-surface="popup"] { --surface-color: var(--red); --surface-bg: var(--red-soft); }
[data-surface="push"] { --surface-color: var(--violet); --surface-bg: var(--violet-soft); }

[data-surface] .surface-dot,
[data-surface] .mini-dot,
.summary-pill[data-surface]::before {
  background: var(--surface-color);
}

.summary-pill[data-surface]::before {
  content: "";
  width: 7px;
  height: 7px;
  margin-right: 6px;
  border-radius: 999px;
}

.calendar-item[data-surface],
.surface-item[data-surface],
.timeline-item[data-surface] {
  border-left-color: var(--surface-color);
}

.status-draft { background: var(--surface-muted); color: var(--muted); }
.status-ready { background: var(--blue-soft); color: var(--blue); }
.status-live { background: var(--green-soft); color: var(--green); }
.status-blocked { background: var(--red-soft); color: var(--red); }

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

@media (max-width: 1240px) {
  .topbar,
  .presets-topbar {
    grid-template-columns: 1fr;
  }

  .view-switcher,
  .preset-search,
  .topbar-actions {
    justify-self: stretch;
    justify-content: flex-start;
  }

  .workspace {
    grid-template-columns: 230px minmax(0, 1fr);
  }

  .detail-panel {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(280px, 0.8fr);
  }
}

@media (max-width: 860px) {
  .topbar,
  .workspace,
  .preset-page {
    padding: 12px;
  }

  .workspace,
  .detail-panel,
  .preset-page {
    grid-template-columns: 1fr;
  }

  .preset-list {
    grid-template-columns: 1fr;
  }

  .left-rail {
    order: 2;
  }

  .calendar-area {
    order: 1;
  }

  .detail-panel {
    order: 3;
  }

  .view-switcher {
    overflow-x: auto;
  }

  .calendar-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .calendar-summary {
    flex-wrap: wrap;
  }

  .calendar-weekdays,
  .calendar-grid.month-view {
    grid-template-columns: 1fr;
  }

  .week-lane {
    grid-template-columns: 1fr;
  }

  .week-lane-label {
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .week-lane-days {
    grid-template-columns: 1fr;
  }

  .week-day-cell {
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .week-day-cell:last-child {
    border-bottom: 0;
  }

  .calendar-weekdays {
    display: none;
  }

  .day-cell,
  .week-view .day-cell,
  .day-view .day-cell {
    min-height: auto;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .preset-field {
    grid-template-columns: 1fr;
  }

  .dialog-actions {
    align-items: stretch;
    flex-direction: column-reverse;
  }

  .dialog-actions > div {
    justify-content: flex-end;
  }
}
