:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --border: #e4e6ef;
  --text: #1c1f2a;
  --text-muted: #6b7086;
  --primary: #4f6df5;
  --primary-hover: #3d5ae0;
  --danger: #e5484d;
  --danger-bg: #fdeceb;
  --radius: 12px;
  --shadow: 0 2px 10px rgba(20, 20, 43, 0.06);
  --today-ring: #4f6df5;
  --cal-header-start: #4f6df5;
  --cal-header-end: #3453e0;
  --weekend-text: #e0567a;
  --weekend-bg: #fdeef2;
  --weekend-bg-hover: #fbe2e9;
  --selection-bg: #eef2ff;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11131c;
    --surface: #1a1d29;
    --border: #2a2d3d;
    --text: #edeef5;
    --text-muted: #9397ab;
    --primary: #6c86ff;
    --primary-hover: #8197ff;
    --danger: #ff6b6f;
    --danger-bg: #3a1f22;
    --shadow: 0 2px 14px rgba(0, 0, 0, 0.4);
    --cal-header-start: #3d4f99;
    --cal-header-end: #2d3b78;
    --weekend-text: #ff8fac;
    --weekend-bg: #2c1f27;
    --weekend-bg-hover: #38232c;
    --selection-bg: #202a4a;
  }
}

:root[data-theme="dark"] {
  --bg: #11131c;
  --surface: #1a1d29;
  --border: #2a2d3d;
  --text: #edeef5;
  --text-muted: #9397ab;
  --primary: #6c86ff;
  --primary-hover: #8197ff;
  --danger: #ff6b6f;
  --danger-bg: #3a1f22;
  --shadow: 0 2px 14px rgba(0, 0, 0, 0.4);
  --cal-header-start: #3d4f99;
  --cal-header-end: #2d3b78;
  --weekend-text: #ff8fac;
  --weekend-bg: #2c1f27;
  --weekend-bg-hover: #38232c;
  --selection-bg: #202a4a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app {
  max-width: 1320px;
  margin: 0 auto;
  padding: 0 16px 40px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 0;
  flex-wrap: wrap;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon { font-size: 28px; }

.brand h1 {
  font-size: 22px;
  margin: 0;
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s ease, transform .05s ease;
}
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-hover); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--border); }

.btn-danger {
  background: var(--danger-bg);
  color: var(--danger);
}
.btn-danger:hover { opacity: 0.85; }

.icon-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 34px;
  height: 34px;
  font-size: 18px;
  cursor: pointer;
  color: var(--text);
}
.icon-btn:hover { background: var(--border); }

.layout {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 20px;
  align-items: start;
}

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
}

.calendar-panel, .sidebar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.calendar-panel { padding: 0 0 16px; }
.sidebar { padding: 18px; }

.calendar-nav {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 18px;
  background: linear-gradient(135deg, var(--cal-header-start), var(--cal-header-end));
  color: #fff;
}

.calendar-nav h2 {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
  flex: 1;
  text-transform: capitalize;
}

.calendar-nav .icon-btn {
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.28);
  color: #fff;
}
.calendar-nav .icon-btn:hover { background: rgba(255, 255, 255, 0.28); }

.calendar-nav .btn-ghost {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: #fff;
}
.calendar-nav .btn-ghost:hover { background: rgba(255, 255, 255, 0.24); }

.calendar-hint {
  font-size: 12px;
  color: var(--text-muted);
  padding: 10px 18px 0;
  margin: 0;
}

.weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  padding: 14px 10px 6px;
  gap: 4px;
}
.weekdays span {
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 700;
  padding: 4px 0;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-radius: 6px;
}
.weekdays span.weekend {
  color: var(--weekend-text);
  background: var(--weekend-bg);
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-auto-rows: minmax(92px, auto);
  gap: 4px;
  padding: 0 10px;
  user-select: none;
}

.day-cell {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-height: 92px;
  background: var(--surface);
  cursor: pointer;
  transition: background .1s ease, box-shadow .1s ease;
}
.day-cell:hover { background: var(--bg); }

.day-cell.weekend { background: var(--weekend-bg); }
.day-cell.weekend:hover { background: var(--weekend-bg-hover); }

.day-cell.outside {
  opacity: 0.4;
}

.day-cell.today {
  box-shadow: inset 0 0 0 2px var(--today-ring);
}

.day-cell.selecting {
  background: var(--selection-bg) !important;
  box-shadow: inset 0 0 0 2px var(--primary);
}

.day-num {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
}
.day-cell.today .day-num { color: var(--primary); }

.trip-chip {
  font-size: 11px;
  line-height: 1.3;
  padding: 3px 6px;
  border-radius: 5px;
  color: #fff;
  cursor: pointer;
  overflow: hidden;
}
.trip-chip:hover { filter: brightness(1.08); }
.chip-place {
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chip-note {
  font-weight: 400;
  opacity: 0.9;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 10px;
}

/* A day fully taken by one trip — the whole square is that trip's color. */
.day-cell.filled {
  border-color: transparent;
  color: #fff;
  cursor: pointer;
  justify-content: flex-start;
}
.day-cell.filled:hover { filter: brightness(1.06); }
.day-cell.filled .day-num { color: rgba(255, 255, 255, 0.85); }
.day-cell.filled.today { box-shadow: inset 0 0 0 2px #fff; }

.day-fill-label {
  margin-top: 2px;
  color: #fff;
  overflow: hidden;
}
.day-fill-label .chip-place {
  font-size: 12px;
  white-space: normal;
}
.day-fill-label .chip-note {
  font-size: 10px;
  white-space: normal;
}

/* Several trips overlap the same day — split the square into bands. */
.day-cell.multi {
  padding: 0;
  gap: 0;
}
.day-cell.multi .day-num {
  position: absolute;
  margin: 6px 0 0 6px;
  color: var(--text-muted);
  text-shadow: 0 0 3px rgba(255, 255, 255, 0.6);
  z-index: 1;
}
.day-cell.multi { position: relative; }
.day-bands {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
}
.day-band {
  flex: 1;
  display: flex;
  align-items: center;
  padding: 2px 6px;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}
.day-band:first-child { padding-left: 24px; }
.day-band:hover { filter: brightness(1.08); }
.day-more {
  position: absolute;
  bottom: 2px;
  right: 6px;
  font-size: 10px;
  color: #fff;
  background: rgba(0, 0, 0, 0.35);
  padding: 1px 5px;
  border-radius: 4px;
  z-index: 1;
}

.sidebar h3 {
  font-size: 14px;
  margin: 4px 0 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.sidebar h3:not(:first-child) { margin-top: 20px; }

.trip-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.trip-card {
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
  background: var(--bg);
}
.trip-card:hover { background: var(--border); }

.trip-card .name {
  font-weight: 600;
  font-size: 13px;
}
.trip-card .meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.empty-hint {
  color: var(--text-muted);
  font-size: 13px;
  padding: 8px 0;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 20, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}
.modal-overlay.hidden { display: none; }

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow);
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.modal-header h3 { margin: 0; font-size: 17px; }

#tripForm label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 12px;
}

#tripForm input[type="text"],
#tripForm input[type="date"],
#tripForm textarea {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}
#tripForm textarea { resize: vertical; }

.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.color-picker {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}
.color-swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
}
.color-swatch.selected {
  border-color: var(--text);
}

.modal-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}
.spacer { flex: 1; }
.hidden { display: none !important; }

/* ---------- Auth screen ---------- */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 24px;
  width: 100%;
  max-width: 380px;
}
.auth-card .brand {
  justify-content: center;
  margin-bottom: 18px;
}
.auth-form label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 14px;
}
.auth-form input {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 10px 11px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}
.btn-block { width: 100%; margin-top: 4px; }
.auth-form .btn-block + .btn-block { margin-top: 8px; }
.hint {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0 0 14px;
  line-height: 1.5;
}
.auth-footnote {
  margin-top: 18px;
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.5;
}
.form-error {
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 13px;
  padding: 8px 10px;
  border-radius: 8px;
  margin: -4px 0 12px;
}
.form-success {
  background: #e9f9ee;
  color: #17b26a;
  font-size: 13px;
  padding: 8px 10px;
  border-radius: 8px;
  margin: 8px 0;
}

/* ---------- Topbar extras ---------- */
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.whoami {
  font-size: 13px;
  color: var(--text-muted);
}

/* ---------- History modal ---------- */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 60vh;
  overflow-y: auto;
}
.history-row {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--bg);
}
.history-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}
.history-action {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 2px 7px;
  border-radius: 5px;
}
.history-insert { background: #e9f9ee; color: #17b26a; }
.history-update { background: #fff4e5; color: #f79009; }
.history-delete { background: var(--danger-bg); color: var(--danger); }
.history-when { font-size: 12px; color: var(--text-muted); }
.history-who { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.history-diff {
  margin: 4px 0 0;
  padding-left: 18px;
  font-size: 12px;
}
.history-diff li { margin-bottom: 2px; }

/* ---------- Users / admin panel ---------- */
.modal-wide { max-width: 560px; }
.mfa-gate { text-align: center; padding: 10px 0; }
.mfa-gate .auth-form { max-width: 260px; margin: 14px auto 0; text-align: left; }
.invite-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.invite-form input[type="email"] {
  flex: 1;
  min-width: 180px;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
.invite-form select {
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
}
.users-table {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.user-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}
.user-email { font-size: 13px; font-weight: 600; }
.user-role { font-size: 12px; color: var(--text-muted); }
.user-actions { display: flex; gap: 6px; align-items: center; }
.user-actions select {
  padding: 5px 6px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
}
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ---------- PIN / links / users (v2) ---------- */
.pin-input {
  text-align: center;
  font-size: 22px !important;
  letter-spacing: 0.5em;
  padding-left: 0.5em !important;
}
.btn-link {
  background: transparent;
  color: var(--text-muted);
  font-weight: 500;
}
.btn-link:hover { color: var(--text); }
.user-row { grid-template-columns: 1fr; }
.user-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.user-actions { flex-wrap: wrap; }
.invite-form input[type="text"] {
  flex: 1;
  min-width: 140px;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

/* ---------- Phones / PWA ---------- */
body { padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }
.calendar-grid { touch-action: manipulation; -webkit-user-select: none; }
input, select, textarea { font-size: 16px; } /* avoid iOS zoom on focus */

@media (max-width: 600px) {
  .app { padding: 0 8px 28px; }
  .topbar { padding: 14px 0; }
  .brand h1 { font-size: 18px; }
  .calendar-nav { padding: 12px 12px; gap: 6px; }
  .calendar-nav h2 { font-size: 16px; }
  .weekdays, .calendar-grid { padding-left: 4px; padding-right: 4px; gap: 2px; }
  .calendar-grid { grid-auto-rows: minmax(64px, auto); }
  .day-cell { min-height: 64px; padding: 3px; border-radius: 6px; }
  .day-num { font-size: 11px; }
  .day-fill-label .chip-place { font-size: 10px; }
  .day-fill-label .chip-note { display: none; }
  .day-band { font-size: 8px; padding: 1px 3px; }
  .day-band:first-child { padding-left: 16px; }
  .topbar-actions { width: 100%; }
  .whoami { width: 100%; }
}

/* ---------- Attachments ---------- */
.files-section { margin: 4px 0 12px; }
.files-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.files-title { font-size: 13px; color: var(--text-muted); font-weight: 600; }
.files-head select {
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
}
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 14px 10px;
  text-align: center;
  cursor: pointer;
  background: var(--bg);
  transition: border-color .12s ease, background .12s ease;
}
.drop-zone:hover, .drop-zone:focus-visible { border-color: var(--primary); outline: none; }
.drop-zone.dragover { border-color: var(--primary); background: var(--selection-bg); }
.drop-title { font-weight: 600; font-size: 14px; }
.drop-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.files-list { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.file-row {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  font-size: 13px;
}
.file-icon { font-size: 18px; }
.file-info { min-width: 0; }
.file-name { display: block; color: var(--text); font-weight: 600; text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
a.file-name:hover { color: var(--primary); text-decoration: underline; }
.file-meta { font-size: 11px; color: var(--text-muted); }
.file-row select {
  padding: 4px 6px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  max-width: 150px;
}
.file-kind-badge { font-size: 11px; color: var(--text-muted); background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 2px 6px; white-space: nowrap; }
.file-remove { width: 28px; height: 28px; font-size: 14px; }
.file-row.pending { border-style: dashed; }
.files-status { font-size: 12px; color: var(--primary); margin: 6px 0 0; }
.files-hint { margin: 8px 0 0; }
.trip-card .clip { margin-left: 6px; }

@media (max-width: 600px) {
  .file-row { grid-template-columns: auto 1fr auto; }
  .file-row select, .file-row .file-kind-badge { grid-column: 2; justify-self: start; }
  .file-row .file-remove { grid-row: 1; grid-column: 3; }
}

/* ---------- fixes: narrow screens ---------- */
.modal-actions { flex-wrap: wrap; }
.file-row { grid-template-columns: auto minmax(0, 1fr) auto auto; }
@media (max-width: 600px) {
  .file-row { grid-template-columns: auto minmax(0, 1fr) auto; }
  .modal-actions .spacer { display: none; }
  .modal-actions .btn-primary { margin-left: auto; }
}

/* ---------- Month / year pickers ---------- */
.calendar-nav h2.month-picker {
  display: flex;
  gap: 8px;
  align-items: center;
  text-transform: none;
}
.month-picker select {
  appearance: none;
  -webkit-appearance: none;
  background: rgba(255, 255, 255, 0.16)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='white'/%3E%3C/svg%3E")
    no-repeat right 10px center;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 8px;
  padding: 6px 28px 6px 10px;
  font-size: 16px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
}
.month-picker select:hover { background-color: rgba(255, 255, 255, 0.26); }
.month-picker select:focus-visible { outline: 2px solid #fff; outline-offset: 1px; }
.month-picker option { color: var(--text); background: var(--surface); font-weight: 500; }

@media (max-width: 600px) {
  .month-picker select { font-size: 14px; padding: 5px 24px 5px 8px; }
  .calendar-nav { flex-wrap: wrap; }
  .calendar-nav h2.month-picker { flex: 1 1 auto; gap: 6px; }
  .calendar-nav .btn { padding: 8px 10px; font-size: 13px; }
}


/* ---------- Layout v3: top bar, gear menu, calendar nav, search ---------- */
.topbar { flex-wrap: nowrap; gap: 12px; }
.topbar-main { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; min-width: 0; }
.topbar-main .brand h1 { white-space: nowrap; }

.settings { position: relative; flex: none; }
.settings-btn { width: 40px; height: 40px; font-size: 20px; line-height: 1; }
.settings-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 230px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(20, 20, 43, 0.18);
  padding: 6px;
  z-index: 40;
}
.settings-menu .whoami {
  padding: 8px 10px 10px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
  word-break: break-word;
}
.menu-item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  border-radius: 8px;
  padding: 9px 10px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  cursor: pointer;
}
.menu-item:hover { background: var(--bg); }
.menu-item.menu-danger { color: var(--danger); }

/* calendar header: ‹  [Сегодня]  [месяц] [год] ........ › */
.calendar-nav { gap: 8px; }
.calendar-nav h2.month-picker { flex: none; }
.calendar-nav #nextMonth { margin-left: auto; }
.btn-today {
  background: #a8e6bd;
  color: #0e4a26;
  border: 1px solid #7fd49d;
  padding: 8px 14px;
}
.btn-today:hover { background: #bff0cf; }

/* "Все поездки" + search on the right of the heading */
.list-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 20px 0 10px; }
.list-head h3 { margin: 0 !important; white-space: nowrap; }
.trip-search {
  flex: 1;
  min-width: 0;
  max-width: 170px;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
}
.trip-search:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: transparent; }

@media (max-width: 600px) {
  .topbar { padding: 12px 0; }
  .topbar-main { gap: 8px; }
  .topbar-main .btn-primary { padding: 8px 12px; font-size: 13px; }
  .calendar-nav { flex-wrap: nowrap; gap: 6px; padding: 12px 10px; }
  .calendar-nav h2.month-picker { flex: 1 1 auto; min-width: 0; gap: 4px; }
  .calendar-nav .month-picker select { min-width: 0; flex: 1 1 auto; padding: 5px 20px 5px 6px; font-size: 13px; background-position: right 6px center; }
  .calendar-nav .btn-today { padding: 7px 8px; font-size: 12px; }
  .calendar-nav #nextMonth { margin-left: 0; }
}

.lbl-short { display: none; }
@media (max-width: 480px) {
  .lbl-long { display: none; }
  .lbl-short { display: inline; }
  .topbar-main { flex-wrap: nowrap; }
  .topbar-main .brand h1 { font-size: 17px; }
}

.calendar-grid, .calendar-grid * { -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }

/* hint now sits under the calendar */
.calendar-hint { padding: 12px 18px 0; text-align: center; }

/* 20-color picker: wraps into rows, comfortable to tap */
.color-picker { flex-wrap: wrap; gap: 8px; }
.color-swatch { width: 28px; height: 28px; flex: none; }
@media (max-width: 600px) { .color-swatch { width: 30px; height: 30px; } }

/* ---------- Print / PDF buttons ---------- */
.calendar-actions { display: flex; justify-content: center; gap: 8px; padding: 10px 18px 0; flex-wrap: wrap; }

/* ---------- Printing: only the month grid, A4 landscape ---------- */
@page { size: A4 landscape; margin: 8mm; }
@media print {
  html, body { background: #fff !important; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .topbar, .sidebar, .calendar-hint, .calendar-actions, #authView, .modal-overlay,
  .calendar-nav .icon-btn, .calendar-nav .btn-today { display: none !important; }
  .app { max-width: none; padding: 0; }
  .layout { display: block; }
  .calendar-panel { box-shadow: none; border: none; border-radius: 0; padding: 0; overflow: visible; }
  .calendar-nav { padding: 8px 12px; background: #4f6df5 !important; justify-content: center; border-radius: 8px; }
  .calendar-nav h2.month-picker { flex: none; }
  .month-picker select { background-image: none; border: none; padding: 0 6px; font-size: 20px; color: #fff; }
  .weekdays, .calendar-grid { padding-left: 0; padding-right: 0; }
  .calendar-grid { grid-auto-rows: minmax(26mm, auto); }
  .day-cell { break-inside: avoid; min-height: 26mm; cursor: default; }
  .day-cell:hover, .day-cell.filled:hover { filter: none; background-color: inherit; }
}

/* ---------- Offline banner ---------- */
.offline-banner {
  background: #fff4e5;
  color: #8a4b00;
  border: 1px solid #f5d199;
  border-radius: 10px;
  padding: 10px 14px;
  margin: 0 0 12px;
  font-size: 13px;
  line-height: 1.45;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .offline-banner { background: #3a2a10; color: #ffd9a0; border-color: #6b4a1a; }
}
@media print { .offline-banner { display: none !important; } }

.menu-note { padding: 0 10px 8px; margin-top: -2px; font-size: 11.5px; color: var(--text-muted); line-height: 1.4; }
.menu-note:empty { display: none; }

/* ---------- In-app file viewer ---------- */
.file-viewer { position: fixed; inset: 0; z-index: 80; display: flex; flex-direction: column; background: #20232e; color: #fff; }
.file-viewer.hidden { display: none; }
.viewer-bar {
  display: flex; align-items: center; gap: 10px; flex: none;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px; background: #151821; border-bottom: 1px solid rgba(255,255,255,.1);
}
.viewer-title { flex: 1; min-width: 0; font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-close { width: 36px; height: 36px; background: rgba(255,255,255,.12); border-color: rgba(255,255,255,.2); color: #fff; }
.viewer-body { flex: 1; overflow: auto; -webkit-overflow-scrolling: touch; padding: 12px; padding-bottom: calc(12px + env(safe-area-inset-bottom)); text-align: center; }
.viewer-body img { max-width: 100%; height: auto; border-radius: 4px; background: #fff; }
.viewer-body canvas { display: block; margin: 0 auto 12px; max-width: 100%; background: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.4); }
.viewer-body pre { text-align: left; white-space: pre-wrap; word-break: break-word; background: #151821; padding: 12px; border-radius: 8px; font-size: 13px; line-height: 1.5; }
.viewer-note { color: rgba(255,255,255,.75); font-size: 13px; padding: 40px 16px; line-height: 1.6; }
.viewer-card { max-width: 340px; margin: 60px auto 0; }
.viewer-card .big { font-size: 54px; line-height: 1; margin-bottom: 10px; }
.viewer-card .nm { font-weight: 600; word-break: break-word; }
.viewer-card .sub { color: rgba(255,255,255,.7); font-size: 13px; margin: 6px 0 16px; }


/* ====================================================================
   iPhone / Safari
   ==================================================================== */
:root { color-scheme: light dark; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

/* 100vh in Safari includes the hidden toolbars: prefer the dynamic viewport height */
.auth-screen { min-height: 100vh; min-height: 100dvh; }
.modal { max-height: 90vh; max-height: 90dvh; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }

/* notch / home indicator: keep content and dialogs clear of the safe areas */
.app { padding-left: calc(16px + env(safe-area-inset-left)); padding-right: calc(16px + env(safe-area-inset-right)); }
.modal-overlay {
  padding-top: max(16px, env(safe-area-inset-top));
  padding-right: max(16px, env(safe-area-inset-right));
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  padding-left: max(16px, env(safe-area-inset-left));
  overscroll-behavior: contain;
}
.file-viewer { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
@media (max-width: 600px) {
  .app { padding-left: calc(8px + env(safe-area-inset-left)); padding-right: calc(8px + env(safe-area-inset-right)); }
}

/* no double-tap-zoom delay on anything tappable */
button, a, select, input, label, summary, .trip-card, .day-cell, .menu-item, .color-swatch, .drop-zone { touch-action: manipulation; }

/* date fields: iOS gives them an intrinsic width/height that breaks grids and collapses when empty */
input[type="date"] {
  -webkit-appearance: none;
  appearance: none;
  min-width: 0;
  max-width: 100%;
  min-height: 40px;
  line-height: 1.2;
}
input[type="date"]::-webkit-date-and-time-value { text-align: left; min-height: 1.2em; }

/* search field: drop Safari's rounded look and its built-in clear button */
input[type="search"] { -webkit-appearance: none; appearance: none; border-radius: 8px; }
input[type="search"]::-webkit-search-cancel-button,
input[type="search"]::-webkit-search-decoration { -webkit-appearance: none; display: none; }

/* iOS zooms the whole page when a field with text smaller than 16px gets focus */
@media (pointer: coarse) {
  input:not(.pin-input), select, textarea { font-size: 16px !important; }
  .calendar-nav .month-picker select { padding: 5px 20px 5px 8px; }
}


/* ---- very narrow phones (iPhone SE 1st gen, 320px) and grid items that refused to shrink ---- */
.btn { white-space: nowrap; }
.topbar-main .brand { min-width: 0; }
.topbar-main .brand h1 { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.row > label { min-width: 0; }
.month-picker select { flex: 0 0 auto; }
.calendar-nav .month-picker select:first-child { flex: 1 1 auto; min-width: 0; }

@media (max-width: 340px) {
  .topbar-main { gap: 6px; }
  .topbar-main .brand h1 { font-size: 15px; }
  .topbar-main .brand-icon { display: none; }
  .calendar-nav { flex-wrap: wrap; row-gap: 8px; }
  .calendar-nav #prevMonth { order: 1; }
  .calendar-nav .btn-today { order: 2; flex: 1 1 auto; }
  .calendar-nav #nextMonth { order: 3; margin-left: 0; }
  .calendar-nav h2.month-picker { order: 4; flex: 1 1 100%; }
}

/* week columns must be allowed to shrink below their text; long names wrap or break instead of widening the grid */
.weekdays, .calendar-grid { grid-template-columns: repeat(7, minmax(0, 1fr)); }
.day-cell { min-width: 0; overflow: hidden; }
.day-fill-label, .day-fill-label .chip-place, .day-fill-label .chip-note { min-width: 0; overflow-wrap: anywhere; word-break: break-word; }
@media (max-width: 600px) {
  .day-fill-label .chip-place { font-size: 9.5px; line-height: 1.2; hyphens: auto; -webkit-hyphens: auto; }
}
