/* File: public/style.css */
:root {
  --paper: #FAF7F1;
  --surface: #FFFFFF;
  --border: #E3DCCB;
  --ink: #211D17;
  --ink-muted: #6E6656;
  --sidebar-bg: #1B211C;
  --sidebar-hover: #2A332B;
  --sidebar-text: #C9CDBE;
  --accent: #C1662B;
  --accent-dark: #A8531F;
  --teal: #3F6E64;
  --danger: #A14257;
  --danger-bg: #F3DCE0;
  --ok: #4C6B3B;
  --ok-bg: #E4EDDD;
  --warn: #8C6D14;
  --warn-bg: #F5EBC9;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Manrope', sans-serif;
  background: var(--paper);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, .serif { font-family: 'Fraunces', serif; margin: 0; }
a { color: inherit; text-decoration: none; }
table { border-collapse: collapse; width: 100%; }

.app-shell { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: 252px;
  min-width: 252px;
  background: var(--sidebar-bg);
  color: #fff;
  padding: 28px 16px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px; background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-family: 'Fraunces', serif; font-weight: 700; color: #fff; font-size: 17px;
}
.brand-name { font-family: 'Fraunces', serif; font-size: 19px; font-weight: 600; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-link {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px;
  border-radius: 10px; font-size: 14px; font-weight: 600; color: var(--sidebar-text);
}
.nav-link:hover { color: #fff; background: var(--sidebar-hover); }
.nav-link.active { background: var(--sidebar-hover); color: #fff; }
.nav-link.nav-soon { opacity: .5; cursor: default; }
.nav-link.nav-soon:hover { background: none; color: var(--sidebar-text); }
.soon-badge { margin-left: auto; font-size: 9px; background: #2E372F; padding: 2px 6px; border-radius: 999px; }
.sidebar-footer { margin-top: auto; }
.sidebar-user { display: flex; align-items: center; gap: 10px; padding: 14px 8px 0 8px; border-top: 1px solid #2A332B; }
.sidebar-user-name { font-size: 13px; font-weight: 700; }
.sidebar-logout { font-size: 11px; color: #8B917F; }
.sidebar-logout:hover { color: #fff; }

/* Main */
.main { flex-grow: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  padding: 28px 36px 20px 36px; display: flex; align-items: flex-start; justify-content: space-between;
  border-bottom: 1px solid var(--border); background: var(--paper); flex-wrap: wrap; gap: 12px;
}
.topbar h1 { font-size: 26px; font-weight: 600; }
.topbar .subtitle { margin: 6px 0 0 0; color: var(--ink-muted); font-size: 14px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.content { flex-grow: 1; padding: 26px 36px 40px 36px; }

/* Building blocks */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; }
.stat-row { display: flex; gap: 18px; margin-bottom: 22px; flex-wrap: wrap; }
.stat-card { padding: 18px 20px; flex: 1; min-width: 200px; }
.stat-label { font-size: 12px; color: var(--ink-muted); font-weight: 700; letter-spacing: .03em; text-transform: uppercase; }
.stat-value { font-family: 'Fraunces', serif; font-size: 26px; font-weight: 600; margin-top: 8px; }
.stat-sub { font-size: 12px; color: var(--ink-muted); margin-top: 4px; }

.btn {
  display: inline-flex; align-items: center; gap: 7px; border-radius: 10px; padding: 10px 16px;
  font-weight: 700; font-size: 13px; font-family: 'Manrope', sans-serif; cursor: pointer; border: none;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-ghost { background: #fff; color: var(--ink); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--paper); }
.btn-danger { background: var(--danger-bg); color: var(--danger); border: 1px solid #E8C3CB; }
.btn-danger:hover { background: #EFC9D1; }
.btn-sm { padding: 6px 11px; font-size: 12px; }
.btn-icon { padding: 7px; }

.pill {
  display: inline-flex; align-items: center; border-radius: 999px; font-size: 12px; font-weight: 700; padding: 4px 10px;
}
.avatar {
  width: 30px; height: 30px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 12px; color: #fff; flex-shrink: 0;
}

table.data-table th {
  text-align: left; font-size: 11px; font-weight: 700; color: var(--ink-muted);
  text-transform: uppercase; letter-spacing: .04em; padding: 10px 14px; border-bottom: 1px solid var(--border);
}
table.data-table td { padding: 12px 14px; border-bottom: 1px solid #F1ECE1; font-size: 14px; vertical-align: middle; }
table.data-table tr:last-child td { border-bottom: none; }
table.data-table tr.row-uncategorized { background: #FBF6EC; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label { font-size: 12px; font-weight: 700; color: var(--ink-muted); }
.field input, .field select, .field textarea {
  font-family: 'Manrope', sans-serif; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px;
}
.field-row { display: flex; gap: 14px; }
.field-row .field { flex: 1; }

/* Modal */
.modal-overlay {
  display: none; position: fixed; inset: 0; background: rgba(27,33,28,.5); z-index: 50;
  align-items: center; justify-content: center; padding: 24px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: #fff; border-radius: 16px; width: 100%; max-width: 480px; padding: 26px;
  max-height: 90vh; overflow-y: auto;
}
.modal h2 { font-size: 19px; margin-bottom: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

.alert { background: #fde8e8; color: #9b1c1c; padding: 10px 14px; border-radius: 8px; margin-bottom: 18px; font-size: 13px; }
.alert-ok { background: var(--ok-bg); color: var(--ok); }
.muted { color: var(--ink-muted); font-size: 13px; }
.empty-state { text-align: center; padding: 40px 20px; color: var(--ink-muted); }

.login-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--sidebar-bg); }
.login-card { background: #fff; border-radius: 18px; padding: 36px; width: 100%; max-width: 380px; }

/* Calendar month grid. minmax(0, 1fr) — not plain 1fr — is the important
   part: grid tracks default to a content-based minimum width, so a long
   event title could force a column wider than its fair share and push
   Saturday/Sunday past the card's edge, where they'd be silently clipped
   (not just scrolled out of view). */
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.cal-day-header {
  text-align: center; padding: 10px 0; font-size: 12px; font-weight: 700; color: var(--ink-muted);
}
.cal-day-header.is-today { background: #F1ECE1; border-radius: 8px; color: var(--ink); }
.cal-day {
  min-height: 110px; min-width: 0; overflow: hidden;
  border-right: 1px solid #F1ECE1; border-bottom: 1px solid #F1ECE1; padding: 8px;
  box-sizing: border-box;
}
.cal-day-num { font-size: 12px; font-weight: 700; margin-bottom: 6px; }
.cal-event-chip {
  border-radius: 5px; padding: 3px 6px; font-size: 11px; font-weight: 700; margin-bottom: 4px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Travel itinerary week view: a time-of-day grid, days as columns —
   built the same way as most calendar apps' week view (absolute-positioned
   blocks within a fixed-height day column, sized/placed by minute offset). */
.week-grid {
  display: flex; overflow-x: auto; border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); max-height: 640px; overflow-y: auto;
}
.week-hours-col {
  flex-shrink: 0; width: 52px; position: sticky; left: 0; z-index: 3;
  background: var(--surface); border-right: 1px solid var(--border);
}
.week-hour-label {
  font-size: 10px; color: var(--ink-muted); text-align: right; padding-right: 6px;
  box-sizing: border-box; border-bottom: 1px solid #F1ECE1; position: relative; top: -6px;
}
.week-day-col { flex-shrink: 0; width: 160px; border-right: 1px solid #F1ECE1; }
.week-day-header {
  height: 44px; box-sizing: border-box; border-bottom: 1px solid var(--border); padding: 5px 8px;
  font-size: 12px; font-weight: 700; text-align: center; line-height: 1.3;
  position: sticky; top: 0; z-index: 2; background: var(--surface);
}
.week-unscheduled {
  padding: 6px 8px; border-bottom: 1px solid var(--border); background: #FBFAF7;
  display: flex; flex-direction: column; gap: 4px;
}
.week-item-chip {
  border-radius: 5px; padding: 3px 6px; font-size: 10.5px; font-weight: 700; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.week-day-body { position: relative; }
.week-hour-row { border-bottom: 1px solid #F1ECE1; box-sizing: border-box; }
.week-item-block {
  position: absolute; left: 3px; right: 3px; border-radius: 6px; padding: 2px 6px;
  font-size: 10.5px; font-weight: 700; color: #fff; overflow: hidden;
  white-space: nowrap; text-overflow: ellipsis; cursor: pointer; box-shadow: 0 1px 3px rgba(0,0,0,.15);
}

/* Mobile: sidebar becomes a slide-in drawer instead of a fixed column.
   Toggled by a plain checkbox (#sidebarToggle in layout_header.php) so
   navigation/logout never depend on JavaScript loading correctly. */
.sidebar-toggle-checkbox { display: none; }
.menu-toggle {
  display: none;
  align-items: center; justify-content: center;
  width: 38px; height: 38px; flex-shrink: 0;
  border-radius: 10px; border: 1px solid var(--border); background: #fff;
  cursor: pointer; color: var(--ink);
}
.sidebar-backdrop { display: none; }

@media (max-width: 860px) {
  .sidebar {
    position: fixed;
    top: 0; left: 0;
    height: 100vh;
    z-index: 110;
    transform: translateX(-100%);
    transition: transform .25s ease;
    box-shadow: 2px 0 24px rgba(0,0,0,.25);
  }
  .sidebar-toggle-checkbox:checked ~ .app-shell .sidebar { transform: translateX(0); }

  .sidebar-backdrop {
    display: block;
    position: fixed; inset: 0;
    background: rgba(27,33,28,.5);
    z-index: 100;
    opacity: 0; pointer-events: none;
    transition: opacity .2s ease;
    cursor: pointer;
  }
  .sidebar-toggle-checkbox:checked ~ .app-shell .sidebar-backdrop { opacity: 1; pointer-events: auto; }

  .menu-toggle { display: inline-flex; }

  .main { width: 100%; }
  .topbar { padding: 18px 18px 16px 18px; }
  .topbar h1 { font-size: 20px; }
  .content { padding: 16px 18px 32px 18px; }

  .stat-row { flex-direction: column; }
  .stat-card { min-width: 0; }
  .field-row { flex-direction: column; gap: 0; }
  .modal { max-width: 100%; margin: 0 8px; }
  table.data-table { font-size: 13px; }

  /* Calendar month grid: the fixed min-height + up to 2 event chips per
     day meant Sat/Sun could get squeezed past the card's edge and clipped
     invisibly (grid tracks default to a content-based minimum width
     unless told otherwise). minmax(0, 1fr) fixes the overflow; the rest
     just makes busy months more compact on a small screen. */
  .cal-day { min-height: 64px !important; padding: 5px !important; }
  .cal-day-num { font-size: 11px !important; margin-bottom: 3px !important; }
  .cal-event-chip { font-size: 9.5px !important; padding: 2px 4px !important; margin-bottom: 2px !important; }
  .cal-day-header { padding: 6px 2px !important; font-size: 10px !important; }

  /* Travel week grid: narrower columns and shorter hour rows so a trip
     fits on a phone screen without the day columns getting unreadably thin. */
  .week-day-col { width: 110px !important; }
  .week-hours-col { width: 40px !important; }
  .week-day-header { font-size: 10.5px !important; }
  .week-item-block, .week-item-chip { font-size: 9.5px !important; }
}