  *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

  :root {
    --bg:      #0a0a0f;
    --gold:    #c9a96e;
    --text:    #f0ece4;
    --muted:   #555;
    --dim:     #333;
    --line:    #141414;
    --card-bg: #0d0d12;
    --green:   #4caf7d;
    --amber:   #e6a817;
    --red:     #e05c5c;
  }

  html, body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Georgia', 'Times New Roman', serif;
    min-height: 100vh;
    overflow-x: hidden;
  }

  /* ── NAV ── */
  nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 48px;
    border-bottom: 1px solid var(--line);
  }
  .nav-logo { color: var(--gold); font-family: sans-serif; font-size: 11px; letter-spacing: 4px; text-transform: uppercase; }
  .nav-sub  { color: var(--muted); font-family: sans-serif; font-size: 10px; letter-spacing: 2px; text-transform: uppercase; }
  .nav-date { color: var(--muted); font-family: sans-serif; font-size: 10px; }

  /* ── LAYOUT ── */
  .page-body {
    min-height: calc(100vh - 57px);
    display: flex;
    flex-direction: column;
  }

  /* ── CALENDAR PANEL ── */
  .calendar-panel {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: calc(100vh - 108px);
  }
  .panel-header {
    padding: 24px 40px 20px;
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: baseline;
    gap: 16px;
  }
  .panel-title {
    font-family: sans-serif;
    font-size: 9px;
    letter-spacing: 3px;
    text-transform: uppercase;
    color: var(--gold);
  }
  .panel-hint {
    font-family: sans-serif;
    font-size: 9px;
    color: var(--muted);
  }
  .calendar-header {
    align-items: center;
    justify-content: space-between;
    gap: 18px;
  }
  .calendar-title-wrap {
    display: flex;
    align-items: baseline;
    gap: 16px;
    min-width: 0;
    white-space: nowrap;
  }
  .calendar-controls {
    display: flex;
    align-items: center;
    gap: 6px;
    font-family: sans-serif;
  }
  .calendar-view-btn,
  .calendar-nav-btn,
  .mobile-calendar-open {
    min-height: 32px;
    border: 1px solid var(--dim);
    background: var(--card-bg);
    color: var(--muted);
    font-family: sans-serif;
    font-size: 9px;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    cursor: pointer;
    text-decoration: none;
  }
  .calendar-view-btn {
    padding: 0 12px;
  }
  .calendar-view-btn.active {
    border-color: var(--gold);
    color: var(--gold);
  }
  .calendar-nav-btn {
    width: 32px;
    font-size: 15px;
    line-height: 1;
  }
  .calendar-add-btn {
    min-width: 92px;
    background: var(--gold);
    border-color: var(--gold);
    color: var(--bg);
    font-weight: 700;
  }
  .calendar-period-label {
    min-width: 74px;
    color: var(--muted);
    font-size: 9px;
    letter-spacing: 0.8px;
    text-align: center;
  }
  .mobile-calendar-open {
    display: none;
    align-items: center;
    justify-content: center;
    margin: 12px 16px 0;
    min-height: 42px;
    color: var(--gold);
  }
  .calendar-embed {
    flex: 1;
    padding: 0;
    min-height: calc(100vh - 158px);
  }
  .calendar-frame,
  .quarter-month iframe {
    width: 100%;
    height: 100%;
    min-height: calc(100vh - 158px);
    border: none;
    filter: invert(1) hue-rotate(180deg) brightness(0.88) contrast(0.92);
  }
  .quarter-grid {
    display: none;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    height: 100%;
    min-height: calc(100vh - 158px);
    border-top: 1px solid transparent;
  }
  .quarter-month {
    min-width: 0;
    border-left: 1px solid var(--line);
    display: flex;
    flex-direction: column;
  }
  .quarter-month:first-child { border-left: none; }
  .quarter-month-title {
    padding: 10px 14px;
    border-bottom: 1px solid var(--line);
    color: var(--gold);
    font-family: sans-serif;
    font-size: 8px;
    letter-spacing: 2px;
    text-transform: uppercase;
  }
  .quarter-month iframe {
    flex: 1;
    min-height: calc(100vh - 204px);
  }
  .calendar-embed.quarter-mode .calendar-frame { display: none; }
  .calendar-embed.quarter-mode .quarter-grid { display: grid; }
  .embed-placeholder {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 60px 40px;
    color: var(--muted);
    font-family: sans-serif;
    font-size: 11px;
    text-align: center;
    line-height: 1.8;
  }
  .embed-placeholder .icon { font-size: 36px; opacity: 0.3; }
  .embed-placeholder code {
    background: var(--card-bg);
    padding: 10px 18px;
    font-size: 10px;
    color: var(--gold);
    letter-spacing: 0.5px;
    border: 1px solid var(--dim);
    display: block;
    text-align: left;
    line-height: 1.7;
  }

  /* ── EVENT PANEL ── */
  .event-panel {
    position: fixed;
    top: 57px;
    right: 0;
    bottom: 0;
    z-index: 35;
    width: min(430px, calc(100vw - 24px));
    display: flex;
    flex-direction: column;
    background: var(--bg);
    border-left: 1px solid var(--line);
    box-shadow: -24px 0 60px rgba(0, 0, 0, 0.42);
    transform: translateX(100%);
    transition: transform 0.24s ease;
    will-change: transform;
  }
  body.event-panel-open .event-panel { transform: translateX(0); }
  .event-panel .panel-header {
    padding: 20px 22px 18px;
    justify-content: space-between;
    align-items: center;
  }
  .event-title-wrap { display: flex; flex-direction: column; gap: 6px; }
  .event-panel-close {
    width: 34px;
    height: 34px;
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--dim);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
  }
  .event-panel-close:hover { border-color: var(--gold); color: var(--gold); }

  /* quick stats bar */
  .stats-bar {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    border-bottom: 1px solid var(--line);
  }
  .stat {
    padding: 14px 20px;
    border-right: 1px solid var(--line);
    font-family: sans-serif;
    text-align: center;
  }
  .stat:last-child { border-right: none; }
  .stat-num { font-size: 22px; font-weight: 300; color: var(--text); line-height: 1; }
  .stat-label { font-size: 8px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--muted); margin-top: 4px; }

  /* event list */
  .event-list {
    padding: 18px 22px;
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .event-group-label {
    font-family: sans-serif;
    font-size: 7px;
    letter-spacing: 3px;
    text-transform: uppercase;
    color: var(--muted);
    margin: 16px 0 10px;
  }
  .event-group-label:first-child { margin-top: 0; }

  .event-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px;
    border: 1px solid transparent;
    background: var(--card-bg);
    margin-bottom: 4px;
    cursor: pointer;
    transition: border-color 0.2s;
  }
  .event-item:hover { border-color: var(--dim); }
  .event-item.done { opacity: 0.4; }
  .event-item.done .event-name { text-decoration: line-through; }

  .event-check {
    width: 14px;
    height: 14px;
    border: 1px solid var(--dim);
    border-radius: 2px;
    flex-shrink: 0;
    margin-top: 1px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, border-color 0.15s;
  }
  .event-item.done .event-check { background: var(--green); border-color: var(--green); }
  .event-item.done .event-check::after { content: '✓'; font-size: 8px; color: #0a0a0f; }

  .event-body { flex: 1; min-width: 0; }
  .event-name { font-family: sans-serif; font-size: 11px; color: var(--text); line-height: 1.4; }
  .event-note {
    font-family: sans-serif;
    font-size: 10px;
    color: #555;
    margin-top: 3px;
    line-height: 1.5;
    overflow-wrap: anywhere;
  }
  .event-meta { display: flex; gap: 10px; margin-top: 4px; align-items: center; flex-wrap: wrap; }
  .event-owner { font-family: sans-serif; font-size: 9px; color: var(--muted); }
  .badge {
    font-family: sans-serif;
    font-size: 8px;
    letter-spacing: 0.5px;
    padding: 2px 7px;
    border-radius: 2px;
    font-weight: 600;
  }
  .badge-pending  { background: #1a1a22; color: var(--muted); }
  .badge-progress { background: #1e1608; color: var(--amber); }
  .badge-done     { background: #0d1a12; color: var(--green); }
  .badge-urgent   { background: #1a0d0d; color: var(--red); }

  .due { font-family: sans-serif; font-size: 9px; color: var(--muted); }
  .due.soon { color: var(--amber); }
  .due.overdue { color: var(--red); }
  .empty-state {
    border: 1px dashed var(--dim);
    padding: 28px 18px;
    font-family: sans-serif;
    font-size: 11px;
    line-height: 1.6;
    color: var(--muted);
    text-align: center;
  }

  /* add event */
  .add-event-bar {
    border-top: 1px solid var(--line);
    padding: 14px 22px;
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    background: #0b0b10;
  }
  .event-date-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .owner-picker {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }
  .owner-choice {
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    min-height: 32px;
    border: 1px solid var(--dim);
    background: var(--card-bg);
    color: var(--muted);
    font-family: sans-serif;
    font-size: 9px;
    line-height: 1;
    cursor: pointer;
    user-select: none;
  }
  .owner-choice input {
    width: 10px;
    height: 10px;
    accent-color: var(--gold);
  }
  .owner-choice:has(input:checked) {
    border-color: var(--gold);
    color: var(--text);
  }
  .add-event-input {
    background: var(--card-bg);
    border: 1px solid var(--dim);
    color: var(--text);
    font-family: sans-serif;
    font-size: 11px;
    padding: 8px 12px;
    outline: none;
    transition: border-color 0.2s;
    width: 100%;
    min-width: 0;
  }
  .add-event-input::placeholder { color: #333; }
  .add-event-input:focus { border-color: var(--gold); }
  .add-event-date {
    background: var(--card-bg);
    border: 1px solid var(--dim);
    color: var(--muted);
    font-family: sans-serif;
    font-size: 10px;
    padding: 8px 10px;
    outline: none;
    color-scheme: dark;
    width: 100%;
    min-width: 0;
  }
  .add-event-date:focus { border-color: var(--gold); }
  .add-event-note {
    resize: vertical;
    min-height: 58px;
    max-height: 140px;
    line-height: 1.5;
  }
  .add-event-btn {
    background: var(--gold);
    color: var(--bg);
    border: none;
    min-height: 40px;
    padding: 8px 16px;
    font-family: sans-serif;
    font-size: 9px;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    font-weight: 700;
    cursor: pointer;
    transition: opacity 0.2s;
    white-space: nowrap;
  }
  .add-event-btn:hover { opacity: 0.85; }

  /* event item actions */
  .event-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: auto;
    flex-shrink: 0;
  }
  .event-icon-btn {
    width: 32px;
    height: 32px;
    background: none;
    border: 1px solid var(--dim);
    color: var(--muted);
    font-size: 15px;
    cursor: pointer;
    border-radius: 2px;
    transition: border-color 0.15s, color 0.15s;
    flex-shrink: 0;
    line-height: 1;
  }
  .event-icon-btn:hover { border-color: var(--gold); color: var(--gold); }
  .event-delete-btn:hover { border-color: var(--red); color: var(--red); }

  /* inline edit form inside event card */
  .event-edit-form {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 12px;
    background: #101018;
    border: 1px solid var(--gold);
    margin-bottom: 4px;
  }
  .event-edit-form input,
  .event-edit-form select,
  .event-edit-form textarea {
    background: var(--card-bg);
    border: 1px solid var(--dim);
    color: var(--text);
    font-family: sans-serif;
    font-size: 11px;
    padding: 7px 10px;
    outline: none;
    width: 100%;
    color-scheme: dark;
  }
  .event-edit-form input:focus,
  .event-edit-form select:focus,
  .event-edit-form textarea:focus { border-color: var(--gold); }
  .event-edit-date-row {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 6px;
    align-items: center;
  }
  .event-edit-date-sep {
    font-family: sans-serif;
    font-size: 9px;
    color: #555;
  }
  .event-edit-actions { display: flex; gap: 8px; }
  .event-edit-save {
    background: var(--gold); color: var(--bg);
    border: none; padding: 10px 16px;
    font-family: sans-serif; font-size: 9px;
    letter-spacing: 1.5px; text-transform: uppercase;
    font-weight: 700; cursor: pointer;
  }
  .event-edit-cancel {
    background: none; color: var(--muted);
    border: 1px solid var(--dim); padding: 10px 16px;
    font-family: sans-serif; font-size: 9px;
    letter-spacing: 1.5px; text-transform: uppercase;
    cursor: pointer;
  }
  .event-edit-cancel:hover { border-color: var(--muted); color: var(--text); }
  .event-edit-delete {
    margin-left: auto;
    background: none;
    color: var(--red);
    border: 1px solid #341616;
    padding: 10px 16px;
    font-family: sans-serif;
    font-size: 9px;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    cursor: pointer;
  }
  .event-edit-delete:hover { border-color: var(--red); }

  /* cal button on event item */
  .event-cal-btn {
    color: var(--muted);
    font-size: 13px;
    cursor: default;
    opacity: 0.55;
  }
  .event-cal-pending { opacity: 0.3; }

  /* ── SHEETS LINK ── */
  .sheets-link-bar {
    border-top: 1px solid var(--line);
    padding: 12px 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  .sheets-link-bar span { font-family: sans-serif; font-size: 9px; color: var(--muted); }
  .sheets-link-bar a {
    font-family: sans-serif;
    font-size: 9px;
    letter-spacing: 1px;
    color: var(--gold);
    text-decoration: none;
    text-transform: uppercase;
  }
  .sheets-link-bar a:hover { opacity: 0.7; }

  /* ── FOOTER ── */
  footer {
    padding: 16px 48px;
    border-top: 1px solid var(--line);
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  .footer-left { color: #222; font-family: sans-serif; font-size: 8px; letter-spacing: 1.5px; text-transform: uppercase; }
  .footer-right a { color: var(--muted); font-family: sans-serif; font-size: 9px; text-decoration: none; letter-spacing: 1px; margin-left: 20px; }
  .footer-right a:hover { color: var(--gold); }

  @media (max-width: 1100px) {
    .calendar-header {
      align-items: flex-start;
      flex-direction: column;
    }
    .calendar-controls {
      width: 100%;
      flex-wrap: wrap;
    }
    .quarter-grid {
      grid-template-columns: 1fr;
      height: auto;
    }
    .quarter-month {
      min-height: 520px;
      border-left: none;
      border-top: 1px solid var(--line);
    }
    .quarter-month:first-child { border-top: none; }
    .quarter-month iframe { min-height: 480px; }
    .owner-picker { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .event-date-grid { grid-template-columns: 1fr; }
  }

  @media (max-width: 760px) {
    nav {
      padding: 13px 16px;
      gap: 6px 12px;
      flex-wrap: wrap;
    }
    .nav-logo { font-size: 10px; letter-spacing: 2.5px; }
    .nav-sub { display: none; }
    .nav-date { width: 100%; font-size: 9px; }
    .page-body { min-height: calc(100vh - 70px); }
    .calendar-panel { min-height: calc(100vh - 116px); }
    .calendar-panel .panel-header {
      padding: 14px 16px 12px;
      gap: 8px;
      flex-wrap: wrap;
    }
    .calendar-title-wrap { gap: 8px; }
    .calendar-view-btn {
      flex: 1;
      min-width: 96px;
    }
    .calendar-period-label {
      order: 10;
      width: 100%;
      text-align: left;
      padding-top: 2px;
    }
    .mobile-calendar-open { display: flex; }
    .panel-hint { font-size: 8px; }
    .calendar-embed,
    .calendar-frame {
      min-height: calc(100vh - 218px);
    }
    .calendar-frame {
      height: calc(100vh - 218px);
      overflow: auto;
      -webkit-overflow-scrolling: touch;
    }
    .quarter-grid,
    .quarter-month,
    .quarter-month iframe {
      min-height: 520px;
    }
    .event-panel {
      top: 0;
      width: 100vw;
      max-width: none;
      border-left: none;
    }
    body.event-panel-open { overflow: hidden; }
    .event-panel .panel-header { padding: 16px; }
    .stats-bar { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .stat { padding: 12px 8px; }
    .event-list { padding: 14px 16px; }
    .event-item {
      padding: 12px 10px;
      gap: 10px;
    }
    .event-actions { flex-direction: column; gap: 2px; }
    .event-icon-btn {
      width: 32px;
      height: 30px;
      font-size: 13px;
    }
    .add-event-bar {
      padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    }
    .event-date-grid,
    .owner-picker {
      grid-template-columns: 1fr;
    }
    .add-event-btn {
      width: 100%;
      min-height: 44px;
      order: 10;
    }
    .event-edit-date-row { grid-template-columns: 1fr; }
    .event-edit-date-sep { display: none; }
    .event-edit-actions {
      display: grid;
      grid-template-columns: 1fr 1fr;
    }
    .event-edit-actions button { min-height: 42px; }
    .event-edit-delete {
      grid-column: 1 / -1;
      margin-left: 0;
    }
    footer {
      padding: 14px 16px;
      flex-direction: column;
      align-items: flex-start;
      gap: 10px;
    }
    .footer-right a { margin: 0 16px 0 0; }
  }
