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

:root {
  --blue: #185FA5;
  --blue-dark: #0C447C;
  --blue-light: #dbeafe;
  --green: #065f46;
  --green-bg: #d1fae5;
  --red: #991b1b;
  --red-bg: #fee2e2;
  --gray-bg: #f5f5f3;
  --border: #e0e0e0;
  --text: #1a1a1a;
  --muted: #666;
  --radius: 10px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--gray-bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── LOGIN ─────────────────────────────────────────── */
.login-page {
  display: flex; align-items: center; justify-content: center;
  padding: 2rem 1rem; min-height: 100vh;
}
.login-wrap { width: 100%; max-width: 420px; }
.login-brand { text-align: center; margin-bottom: 2rem; }
.login-brand h1 { font-size: 20px; font-weight: 600; margin-bottom: 6px; }
.brand-sub { font-size: 13px; color: var(--muted); }
.login-card {
  background: #fff; border-radius: var(--radius);
  padding: 2rem; box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}
.login-label { font-size: 15px; font-weight: 600; margin-bottom: 1.25rem; }
.login-card label {
  font-size: 13px; font-weight: 500; color: var(--muted);
  display: block; margin-bottom: 5px;
}
.login-card input {
  width: 100%; font-size: 16px; /* 16px prevents iOS zoom */ padding: 12px;
  border: 1px solid var(--border); border-radius: 8px; outline: none;
}
.login-card input:focus {
  border-color: var(--blue); box-shadow: 0 0 0 3px rgba(24,95,165,0.1);
}
.btn-primary {
  width: 100%; margin-top: 1.25rem; padding: 13px;
  background: var(--blue); color: #fff; border: none; border-radius: 8px;
  font-size: 15px; font-weight: 600; cursor: pointer;
}
.btn-primary:hover { background: var(--blue-dark); }
.btn-primary:disabled { opacity: 0.5; cursor: default; }
.login-footer {
  font-size: 12px; color: var(--muted); text-align: center;
  margin-top: 1.25rem; line-height: 1.6;
}
.login-footer a { color: var(--blue); text-decoration: none; }
.error-msg {
  background: var(--red-bg); color: var(--red); font-size: 13px;
  padding: 9px 12px; border-radius: 7px; margin-bottom: 1rem;
}

/* ── APP SHELL ─────────────────────────────────────── */
.app-header {
  background: #fff; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
}
.header-inner {
  max-width: 820px; margin: 0 auto; padding: 0 1rem;
  height: 52px; display: flex; align-items: center; justify-content: space-between;
  gap: 8px;
}
.header-brand {
  display: flex; align-items: center; gap: 8px;
  font-size: 14px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0;
}
.header-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.user-name {
  font-size: 12px; color: var(--muted);
  max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.btn-ghost {
  background: none; border: 1px solid var(--border); border-radius: 7px;
  font-size: 13px; padding: 6px 10px; cursor: pointer; color: var(--text);
  white-space: nowrap;
}
.btn-ghost:hover { background: var(--gray-bg); }

.app-main { max-width: 820px; margin: 0 auto; padding: 1.5rem 1rem 5.5rem; }

.page-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 1.5rem; gap: 0.75rem; flex-wrap: wrap;
}
.page-header h2 { font-size: 18px; font-weight: 600; }
.page-sub { font-size: 13px; color: var(--muted); margin-top: 3px; }
.status-badge {
  font-size: 12px; font-weight: 500; padding: 5px 12px;
  border-radius: 20px; white-space: nowrap;
}
.badge-confirmed { background: var(--green-bg); color: var(--green); }
.badge-pending { background: #fef3c7; color: #92400e; }

/* ── PREFERENCE CARDS ──────────────────────────────── */
.pref-card {
  background: #fff; border-radius: var(--radius); padding: 1.25rem;
  margin-bottom: 1rem; box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.card-title {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--muted); margin-bottom: 1rem;
}

/* On desktop: label left, control right */
.field-row {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 1rem; padding: 12px 0; border-bottom: 1px solid #f0f0ee;
}
.field-row:last-child { border-bottom: none; padding-bottom: 0; }
.field-row:first-of-type { padding-top: 0; }
.field-meta { flex: 1; min-width: 0; }
.field-label { font-size: 16px; font-weight: 500; line-height: 1.4; }
.required-badge {
  display: inline-block; font-size: 10px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.04em; color: var(--blue); background: #eff6ff;
  border: 1px solid #bfdbfe; border-radius: 4px; padding: 1px 5px;
  vertical-align: middle; margin-left: 6px;
}
.field-hint { font-size: 14px; color: var(--muted); margin-top: 3px; line-height: 1.5; }

.chip-group {
  display: flex; gap: 6px; flex-wrap: wrap;
  justify-content: flex-end; max-width: 360px;
}
.chip {
  padding: 7px 14px; border-radius: 20px; font-size: 13px; cursor: pointer;
  border: 1px solid var(--border); background: #fff; color: var(--text);
  font-family: inherit; transition: all 0.12s;
  /* Larger tap target on mobile */
  min-height: 36px; display: inline-flex; align-items: center;
}
.chip:hover { border-color: var(--blue); color: var(--blue); }
.chip.active { background: var(--blue); color: #fff; border-color: var(--blue); }

.pref-select {
  font-size: 16px; /* prevents iOS zoom */ padding: 9px 10px;
  border-radius: 8px; border: 1px solid var(--border);
  background: #fff; color: var(--text); min-width: 160px; outline: none;
}
.pref-select:focus { border-color: var(--blue); }

.pref-notes {
  width: 100%; font-size: 16px; /* prevents iOS zoom */ padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 8px; background: #fff;
  color: var(--text); resize: vertical; min-height: 80px;
  font-family: inherit; outline: none;
}
.pref-notes:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(24,95,165,0.1); }


/* ── CALENDAR ──────────────────────────────────────── */
.cal-wrap {
  background: #fff; border-radius: var(--radius); padding: 1.25rem;
  margin-bottom: 1rem; box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.cal-wrap .card-title { margin-bottom: 0.5rem; }
.cal-sub { font-size: 13px; color: var(--muted); margin-bottom: 1rem; line-height: 1.5; }
.counter-bar { display: flex; gap: 8px; margin-bottom: 1rem; flex-wrap: wrap; }
.ctr {
  background: var(--gray-bg); border-radius: 8px;
  padding: 8px 12px; flex: 1; min-width: 80px;
}
.ctr label { font-size: 11px; color: #888; display: block; margin-bottom: 2px; }
.ctr span { font-size: 18px; font-weight: 600; }
.ctr span.warn { color: #c0392b; }
.hint { font-size: 12px; color: var(--blue); margin-bottom: 10px; min-height: 18px; line-height: 1.5; }
.hint a { color: #888; cursor: pointer; text-decoration: underline; margin-left: 6px; }

/* Calendar grid — single column on narrow screens, auto-fit on wider */
.months {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px; margin-bottom: 1rem;
}
.month-card { border: 1px solid #eee; border-radius: 10px; padding: 12px; }
.month-title { font-size: 13px; font-weight: 600; margin-bottom: 8px; text-align: center; color: #333; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.dlbl { font-size: 10px; color: #aaa; text-align: center; padding: 2px 0; }
.day {
  font-size: 12px; text-align: center; padding: 6px 2px;
  border-radius: 4px; cursor: pointer; user-select: none;
  /* Bigger tap targets on touch */
  min-height: 30px; display: flex; align-items: center; justify-content: center;
}
.day.empty { cursor: default; pointer-events: none; visibility: hidden; }
.day.disabled { cursor: default; pointer-events: none; color: #ccc; background: none; }
.day:hover { background: var(--blue-light); color: #1e40af; }
.day.taken { background: var(--blue-light); color: #1e40af; cursor: default; }
.day.rs, .day.re { background: var(--blue); color: #fff; font-weight: 600; }
.day.prev { background: var(--blue-light); color: #185FA5; }
.day.ps, .day.pe { background: #2563eb; color: #fff; font-weight: 600; }
.day.over { background: var(--red-bg); color: var(--red); }

.req-list { margin-bottom: 1rem; }
.req-item {
  border: 1px solid #eee; border-radius: 8px; padding: 10px 12px;
  margin-bottom: 8px; background: #fff;
}
.req-top { display: flex; align-items: center; gap: 10px; }
.badge-num {
  width: 28px; height: 28px; border-radius: 50%; background: #f0f0ee;
  border: 1px solid #ddd; font-size: 12px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; cursor: grab; color: #555;
}
.rdates { flex: 1; font-size: 13px; min-width: 0; }
.rdays { font-size: 12px; color: #888; }
.rdel {
  font-size: 22px; color: #bbb; cursor: pointer; line-height: 1;
  padding: 0 6px; flex-shrink: 0;
}
.rdel:hover { color: #e74c3c; }
.req-note { margin-top: 8px; margin-left: 36px; }
.req-note input {
  width: 100%; font-size: 14px; padding: 7px 10px;
  border: 1px solid #eee; border-radius: 6px;
  background: #fafafa; color: var(--text); outline: none; font-family: inherit;
}
.req-note input:focus { border-color: var(--blue); }
.none { font-size: 13px; color: #aaa; padding: 6px 0; }

/* ── SAVE BAR ──────────────────────────────────────── */
.save-bar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 200;
  max-width: 820px; margin: 0 auto;
  display: flex; flex-direction: column; padding: 0.875rem 1.5rem;
  background: #fff; border: 1px solid var(--border); border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: 0 -2px 8px rgba(0,0,0,0.08);
}
.last-confirmed { font-size: 13px; color: var(--muted); }
.btn-save { width: auto; margin-top: 0; padding: 11px 24px; }

.toast {
  background: var(--green-bg); color: var(--green); font-size: 13px;
  padding: 10px 16px; border-radius: 8px; margin-bottom: 1rem;
}
.toast-warn {
  background: #fefce8; color: #854d0e; border: 1px solid #fde68a;
}

/* ── ADMIN ─────────────────────────────────────────── */
.admin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px; margin-bottom: 1.25rem;
}
.metric-card {
  background: #fff; border-radius: var(--radius); padding: 1rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.metric-label { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.metric-value { font-size: 26px; font-weight: 600; }
.metric-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

.admin-card {
  background: #fff; border-radius: var(--radius); padding: 1.25rem;
  margin-bottom: 1rem; box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.admin-card-header {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem;
}
.admin-card-title {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--muted);
}

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--muted); padding: 8px 10px;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
td { padding: 10px; border-bottom: 1px solid #f5f5f3; vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #fafafa; }

.cat-badge { font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 12px; white-space: nowrap; }
.cat-blue   { background: #dbeafe; color: #1e40af; }
.cat-red    { background: #fee2e2; color: #991b1b; }
.cat-sn     { background: #f3e8ff; color: #6b21a8; }
.cat-noct   { background: #e0f2fe; color: #075985; }
.cat-shift  { background: #dcfce7; color: #166534; }
.cat-none   { background: #f5f5f3; color: var(--muted); }

.btn-sm {
  font-size: 12px; padding: 5px 11px; border-radius: 6px;
  border: 1px solid var(--border); background: #fff;
  cursor: pointer; color: var(--text); font-family: inherit; white-space: nowrap;
}
.btn-sm:hover { background: var(--gray-bg); }
.btn-sm.primary { background: var(--blue); color: #fff; border-color: var(--blue); }
.btn-sm.primary:hover { background: var(--blue-dark); }
.btn-sm.danger { color: var(--red); border-color: #fca5a5; }
.btn-sm.danger:hover { background: var(--red-bg); }

.form-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 1rem; }
.form-group { display: flex; flex-direction: column; gap: 5px; flex: 1; min-width: 160px; }
.form-group label { font-size: 12px; font-weight: 500; color: var(--muted); }
.form-group input, .form-group select {
  font-size: 16px; /* prevents iOS zoom */ padding: 9px 10px;
  border: 1px solid var(--border); border-radius: 7px; outline: none; font-family: inherit;
}
.form-group input:focus, .form-group select:focus { border-color: var(--blue); }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.35);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 200; padding: 0;
}
.modal {
  background: #fff; border-radius: var(--radius) var(--radius) 0 0;
  padding: 1.5rem; width: 100%; max-width: 100%;
  max-height: 92vh; overflow-y: auto;
}
.modal h3 { font-size: 16px; font-weight: 600; margin-bottom: 1.25rem; }
.modal-footer { display: flex; gap: 10px; justify-content: flex-end; margin-top: 1.5rem; }
.modal .form-group { min-width: 100%; }

.param-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.param-grid .form-group { min-width: 0; }

.section-divider {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--muted); margin: 1.25rem 0 0.75rem;
}

/* ── MOBILE BREAKPOINT (≤ 600px) ───────────────────── */
@media (max-width: 600px) {

  /* Header — hide user email, compress buttons */
  .user-name { display: none; }
  .btn-ghost { font-size: 12px; padding: 5px 8px; }
  .header-brand { font-size: 13px; }

  /* Main padding */
  .app-main { padding: 1rem 0.75rem 5rem; }

  /* Page header — stack vertically */
  .page-header { flex-direction: column; gap: 0.5rem; margin-bottom: 1rem; }
  .page-header h2 { font-size: 17px; }

  /* Save bar — stack vertically, full-width button */
  .save-bar { flex-direction: column; align-items: stretch; padding: 0.75rem 1rem; gap: 0.5rem; }
  .btn-save { width: 100%; text-align: center; }
  .last-confirmed { text-align: center; }

  /* Preference cards — tighter padding */
  .pref-card { padding: 1rem; }
  .cal-wrap { padding: 1rem; }

  /* Field rows — stack label above chips on mobile */
  .field-row {
    flex-direction: column;
    gap: 0.6rem;
  }
  .chip-group {
    max-width: 100%;
    justify-content: flex-start;
  }
  .pref-select { width: 100%; }

  /* Calendar months — one column on very small screens */
  .months { grid-template-columns: 1fr 1fr; gap: 8px; }
  .month-card { padding: 8px; }
  .month-title { font-size: 12px; }
  .day { font-size: 11px; padding: 5px 1px; min-height: 28px; }
  .dlbl { font-size: 9px; }

  /* Counter bar wraps gracefully */
  .ctr { min-width: 70px; }
  .ctr span { font-size: 16px; }

  /* Admin header buttons — shrink */
  .header-right { gap: 5px; }

  /* Admin table — horizontal scroll with sticky first column */
  .table-wrap { overflow-x: auto; }
  td, th { padding: 8px 8px; }

  /* Modal — sheet from bottom, full width */
  .modal { border-radius: 16px 16px 0 0; padding: 1.25rem; }
  .param-grid { grid-template-columns: 1fr; }

  /* Admin page header */
  .admin-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .metric-value { font-size: 22px; }
  .metric-label { font-size: 11px; }
}

/* ── VERY SMALL (≤ 380px) ──────────────────────────── */
@media (max-width: 380px) {
  .months { grid-template-columns: 1fr; }
  .admin-grid { grid-template-columns: 1fr; }
  .header-inner { padding: 0 0.75rem; }
}

/* ── ADMIN TABS ────────────────────────────────────── */
.admin-tabs {
  display: flex; gap: 4px; margin-bottom: 1.25rem;
  border-bottom: 2px solid var(--border); padding-bottom: 0;
}
.admin-tab {
  padding: 8px 18px; font-size: 13px; font-weight: 500;
  border: none; background: none; cursor: pointer; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -2px;
  border-radius: 6px 6px 0 0; font-family: inherit;
}
.admin-tab:hover { color: var(--text); background: var(--gray-bg); }
.admin-tab.active { color: var(--blue); border-bottom-color: var(--blue); font-weight: 600; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── VACATION BALANCE CARD ─────────────────────────── */
.vac-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px; margin-bottom: 1.25rem;
}
.vac-stat {
  background: #fff; border-radius: var(--radius); padding: 1rem 1.25rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.vac-stat-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 6px; }
.vac-stat-value { font-size: 28px; font-weight: 700; line-height: 1; }
.vac-stat-sub   { font-size: 12px; color: var(--muted); margin-top: 4px; }
.vac-stat.accent .vac-stat-value { color: var(--blue); }
.vac-stat.positive .vac-stat-value { color: var(--green); }
.vac-stat.warning .vac-stat-value { color: #92400e; }

/* Horizontal progress bar for bank fill */
.vac-bar-wrap { margin-top: 8px; height: 6px; background: #e5e7eb; border-radius: 3px; overflow: hidden; }
.vac-bar-fill { height: 100%; border-radius: 3px; background: var(--blue); transition: width 0.4s; }
.vac-bar-fill.warn { background: #f59e0b; }
.vac-bar-fill.full { background: var(--green); }

/* Prediction block */
.vac-predict {
  background: #eff6ff; border: 1px solid #bfdbfe; border-radius: var(--radius);
  padding: 1rem 1.25rem; margin-bottom: 1rem;
}
.vac-predict-title { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: #1e40af; margin-bottom: 0.75rem; }
.vac-predict-row { display: flex; justify-content: space-between; align-items: baseline; font-size: 13px; padding: 3px 0; }
.vac-predict-row span:first-child { color: var(--muted); }
.vac-predict-row span:last-child  { font-weight: 600; }
.vac-predict-total { border-top: 1px solid #bfdbfe; margin-top: 8px; padding-top: 8px; font-size: 15px; font-weight: 700; }

/* Relinquishment list */
.relq-list { display: flex; flex-direction: column; gap: 8px; }
.relq-item {
  display: flex; align-items: center; gap: 10px;
  border: 1px solid #eee; border-radius: 8px; padding: 10px 12px;
  background: #fff; font-size: 13px;
}
.relq-date { font-weight: 600; min-width: 80px; }
.relq-pts  { background: #dbeafe; color: #1e40af; border-radius: 12px; padding: 2px 9px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.relq-hrs  { color: var(--muted); font-size: 12px; white-space: nowrap; }
.relq-note { flex: 1; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.relq-del  { font-size: 20px; color: #ccc; cursor: pointer; padding: 0 4px; flex-shrink: 0; line-height: 1; }
.relq-del:hover { color: #e74c3c; }

/* Charge history table accent */
.charge-credit { color: var(--green); font-weight: 600; }
.charge-debit  { color: var(--red);   font-weight: 600; }

/* Block assignment table */
.pts-input {
  width: 75px; font-size: 14px; padding: 5px 8px;
  border: 1px solid var(--border); border-radius: 6px; outline: none;
  font-family: inherit; text-align: right;
}
.pts-input:focus { border-color: var(--blue); }

/* Inline block-select */
.block-select-bar {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 1rem;
}
.block-select-bar select { font-size: 14px; padding: 7px 10px; border: 1px solid var(--border); border-radius: 7px; outline: none; font-family: inherit; }
.block-select-bar select:focus { border-color: var(--blue); }

/* Status pill for block */
.block-pill {
  display: inline-block; font-size: 11px; font-weight: 600; padding: 3px 10px;
  border-radius: 12px; white-space: nowrap;
}
.block-pill-active    { background: #d1fae5; color: #065f46; }
.block-pill-completed { background: #f5f5f3; color: var(--muted); }

@media (max-width: 600px) {
  .vac-grid { grid-template-columns: 1fr 1fr; }
  .vac-stat-value { font-size: 22px; }
  .admin-tabs { gap: 2px; }
  .admin-tab { padding: 7px 12px; font-size: 12px; }
}
