:root {
  --bg:         #f0f2f5;
  --surface:    #ffffff;
  --surface2:   #f8f9fb;
  --border:     #e2e6ea;
  --border2:    #cdd3da;
  --text:       #1a202c;
  --muted:      #64748b;
  --accent:     #2563eb;
  --accent-lt:  #dbeafe;
  --green:      #16a34a;
  --green-lt:   #dcfce7;
  --red:        #dc2626;
  --radius:     6px;
  --shadow:     0 1px 4px rgba(0,0,0,.08);
  --shadow-md:  0 4px 16px rgba(0,0,0,.12);
  --bar-bg:     #dbeafe;
  --bar-border: #3b82f6;
  --bar-text:   #1e40af;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 13px;
  line-height: 1.4;
}

a { color: var(--accent); text-decoration: none; }

/* ── Topbar ── */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  height: 50px;
  gap: 10px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}
.topbar-brand { font-size: 15px; font-weight: 700; color: var(--text); white-space: nowrap; }
.topbar-nav { display: flex; align-items: center; gap: 4px; }
.nav-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 10px;
  border-radius: var(--radius);
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  display: inline-block;
  line-height: 1.6;
}
.nav-btn:hover { background: var(--accent-lt); border-color: var(--accent); color: var(--accent); text-decoration: none; }
.nav-period { font-size: 13px; font-weight: 600; padding: 0 6px; white-space: nowrap; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.topbar-user { font-size: 12px; color: var(--muted); white-space: nowrap; }

/* ── Buttons ── */
.btn {
  display: inline-block;
  padding: 5px 12px;
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  text-decoration: none;
  line-height: 1.5;
}
.btn:hover { background: var(--accent-lt); border-color: var(--accent); color: var(--accent); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #1d4ed8; border-color: #1d4ed8; color: #fff; }
.btn-sm { padding: 3px 9px; font-size: 11px; }
.btn-full { width: 100%; text-align: center; display: block; }
.btn-danger { color: var(--red); border-color: #fecaca; }
.btn-danger:hover { background: #fef2f2; border-color: var(--red); }

/* ── Stats bar ── */
.statsbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 6px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  position: sticky;
  top: 50px;
  z-index: 90;
  box-shadow: var(--shadow);
}
.stat-tiles { display: flex; gap: 5px; flex-wrap: wrap; }
.stat-tile {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 3px 9px;
  font-size: 12px;
  white-space: nowrap;
}
.stat-tile.is-today { background: var(--accent-lt); border-color: var(--accent); }
.stat-date { font-weight: 600; }
.stat-num { font-size: 14px; font-weight: 800; color: var(--accent); }

/* ── Flash ── */
.flash { padding: 7px 16px; font-size: 12px; border-left: 3px solid; }
.flash-ok  { background: #f0fdf4; border-color: var(--green); color: var(--green); }
.flash-err { background: #fef2f2; border-color: var(--red); color: var(--red); }

/* ── Calendar wrapper ── */
.cal-wrap { overflow-x: auto; padding: 14px 14px 4px; }

.cal-table {
  border-collapse: collapse;
  min-width: 700px;
  width: 100%;
  background: var(--surface);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow);
  table-layout: fixed;
}

.cal-table th,
.cal-table td { border: 1px solid var(--border); }

/* ── Apartment header ── */
.th-apt {
  background: var(--surface2);
  padding: 7px 10px;
  text-align: left;
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  position: sticky;
  left: 0;
  z-index: 30;
  width: 120px;
  min-width: 120px;
  border-right: 2px solid var(--border2);
}
.th-apt-assign {
  background: var(--surface2);
  position: sticky;
  left: 0;
  z-index: 30;
  width: 120px;
  min-width: 120px;
  border-right: 2px solid var(--border2);
}

/* ── Day header ── */
.th-day {
  background: var(--surface2);
  text-align: center;
  padding: 5px 2px;
  width: 70px;
  min-width: 60px;
}
.th-day.is-today   { background: var(--accent-lt); }
.th-day.is-weekend { background: #f5f3ff; }

.d-name {
  display: block;
  font-size: 9px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}
.d-num {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
}
.th-day.is-today .d-num { color: var(--accent); }

/* ── Assign row (per-day dropdown) ── */
.assign-row { background: var(--surface2); }
.th-assign {
  background: var(--surface2);
  padding: 3px 2px;
  text-align: center;
  border-top: none;
}
.th-assign.is-today   { background: #eef5ff; }
.th-assign.is-weekend { background: #f0eeff; }

.assign-dd {
  width: calc(100% - 4px);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 2px;
  font-size: 10px;
  color: var(--text);
  background: var(--surface);
  cursor: pointer;
  height: 22px;
}
.assign-dd:focus { outline: none; border-color: var(--accent); }

/* ── Apartment name cell ── */
.td-apt {
  padding: 0 10px;
  background: var(--surface);
  position: sticky;
  left: 0;
  z-index: 10;
  width: 120px;
  min-width: 120px;
  border-right: 2px solid var(--border2);
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  height: 54px;
  vertical-align: middle;
}

/* ── Day cells ── */
.td-day {
  height: 54px;
  position: relative;
  background: var(--surface);
  padding: 0;
  overflow: visible;
}
.td-day.is-today   { background: #f0f7ff; }
.td-day.is-weekend { background: #fafafa; }

/* ── Booking bars ── */
.bar {
  position: absolute;
  top: 13px;
  bottom: 13px;
  background: var(--bar-bg);
  border-top: 1.5px solid var(--bar-border);
  border-bottom: 1.5px solid var(--bar-border);
  display: flex;
  align-items: center;
  overflow: hidden;
  z-index: 2;
}

/* Arrival: right half, left-rounded cap, extends into next cell for seamless join */
.bar-right {
  left: 50%;
  right: -1px;
  border-left: 1.5px solid var(--bar-border);
  border-radius: 5px 0 0 5px;
}

/* Middle night: seamless, extends 1px past both cell borders */
.bar-full {
  left: -1px;
  right: -1px;
  border-left: none;
  border-right: none;
}

/* Departure: left half, right-rounded cap, extends from previous cell */
.bar-left {
  left: -1px;
  right: 50%;
  border-right: 1.5px solid var(--bar-border);
  border-radius: 0 5px 5px 0;
}

.bar-name {
  font-size: 10px;
  font-weight: 600;
  color: var(--bar-text);
  padding: 0 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  line-height: 1;
}

/* ── Cleaning indicators ── */
/* Centered (back-to-back: between two pills, or standalone) */
.cell-clean {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 5;
  font-size: 14px;
  line-height: 1;
  gap: 1px;
}

.cell-clean-center {
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 6px;
  padding: 2px 4px;
  min-width: 22px;
  text-align: center;
}

/* Right half (after bar-left, departure-only) */
.cell-clean-right {
  left: 53%;
  right: 2px;
}

.clean-name {
  font-size: 8px;
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 56px;
}

/* ── Legend ── */
.legend {
  display: flex;
  gap: 16px;
  padding: 8px 14px 18px;
  flex-wrap: wrap;
  font-size: 11px;
  color: var(--muted);
  align-items: center;
}
.legend-item { display: flex; align-items: center; gap: 5px; }
.leg-bar {
  width: 28px;
  height: 14px;
  background: var(--bar-bg);
  border: 1.5px solid var(--bar-border);
  border-radius: 3px;
  display: inline-block;
}

/* ── Login ── */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
}
.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 32px;
  width: 100%;
  max-width: 360px;
  box-shadow: var(--shadow-md);
}
.login-box h1 { font-size: 20px; margin-bottom: 4px; }
.login-sub { color: var(--muted); font-size: 12px; margin-bottom: 24px; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; font-weight: 500; color: var(--muted); margin-bottom: 4px; }
.field input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
}
.field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-lt); }

.alert { padding: 8px 12px; border-radius: var(--radius); font-size: 13px; margin-bottom: 14px; }
.alert-error { background: #fef2f2; border: 1px solid #fecaca; color: var(--red); }

/* ── Admin pages ── */
.page-wrap { padding: 20px; max-width: 900px; }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.page-header h1 { font-size: 18px; font-weight: 700; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.data-table th {
  text-align: left;
  padding: 10px 14px;
  background: var(--surface2);
  border-bottom: 2px solid var(--border);
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}
.data-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--surface2); }

.actions-cell { display: flex; gap: 6px; align-items: center; }
.role-badge { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.role-admin   { background: #ede9fe; color: #7c3aed; }
.role-cleaner { background: var(--green-lt); color: var(--green); }
code { background: var(--surface2); padding: 1px 5px; border-radius: 3px; font-size: 12px; font-family: monospace; border: 1px solid var(--border); }

/* ── Modal ── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.35);
  display: flex; align-items: center; justify-content: center;
  z-index: 200; padding: 16px;
}
.modal-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; width: 100%; max-width: 400px;
  box-shadow: var(--shadow-md); overflow: hidden;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 16px; border-bottom: 1px solid var(--border);
  font-weight: 600; font-size: 14px;
}
.modal-close { background: none; border: none; font-size: 18px; cursor: pointer; color: var(--muted); padding: 2px 6px; border-radius: 4px; line-height: 1; }
.modal-close:hover { background: var(--surface2); }
.modal-body { padding: 16px; }
.input-field { width: 100%; border: 1px solid var(--border); border-radius: var(--radius); padding: 7px 10px; font-size: 13px; color: var(--text); background: var(--surface); }
.input-field:focus { outline: none; border-color: var(--accent); }
.input-sm { border: 1px solid var(--border); border-radius: var(--radius); padding: 4px 8px; font-size: 12px; color: var(--text); background: var(--surface); height: 28px; }
.input-sm:focus { outline: none; border-color: var(--accent); }
