:root,
body.theme-dark {
  --bg: #09090b;
  --surface: #121214;
  --surface-2: #1c1c1f;
  --hover-bg: #27272a;
  --border: #27272a;
  --border-light: #1f1f23;
  --grid-dash: rgba(255, 255, 255, 0.06);
  --text: #fafafa;
  --text-muted: #a1a1aa;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-soft: rgba(59, 130, 246, 0.14);
  --danger: #f87171;
  --danger-border: rgba(248, 113, 113, 0.35);
  --danger-bg: rgba(248, 113, 113, 0.12);
  --success: #22c55e;
  --success-bg: rgba(34, 197, 94, 0.15);
  --warning: #f59e0b;
  --pill-active-bg: #fafafa;
  --pill-active-text: #09090b;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.45);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.55);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.7);
  --sidebar-w: 236px;
  --hour-w: 72px;
  --sub-col-w: 248px;
  --row-h: 88px;
  color-scheme: dark;
}

body.theme-light {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --hover-bg: #e2e8f0;
  --border: #e2e8f0;
  --border-light: #eef2f6;
  --grid-dash: #f1f5f9;
  --text: #0f172a;
  --text-muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff6ff;
  --danger: #dc2626;
  --danger-border: #fecaca;
  --danger-bg: #fef2f2;
  --success: #16a34a;
  --success-bg: #dcfce7;
  --warning: #d97706;
  --pill-active-bg: #0f172a;
  --pill-active-text: #ffffff;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 6px 20px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 20px 50px rgba(15, 23, 42, 0.16);
  color-scheme: light;
}

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

html, body {
  height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

/* ==================== APP FRAME ==================== */
.app-frame {
  height: 100dvh;
  width: 100%;
  position: relative;
  overflow: hidden;
}

.app-shell {
  display: flex;
  height: 100%;
  width: 100%;
  background: var(--bg);
  position: relative;
}

/* ==================== SIDEBAR (DESKTOP) ==================== */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 18px;
  border-bottom: 1px solid var(--border-light);
  margin-bottom: 14px;
}

.brand-logo {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, #2563eb, #4f46e5);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.28);
}

.brand-name {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.01em;
}

.brand-sub {
  font-size: 11.5px;
  color: var(--text-muted);
}

.nav-menu {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 9px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-weight: 500;
  text-align: left;
  transition: all 0.15s ease;
  position: relative;
}

.nav-item:hover {
  background: var(--surface-2);
  color: var(--text);
}

.nav-item.active {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
}

.nav-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #cbd5e1;
  margin-left: auto;
}

.nav-dot.connected {
  background: var(--success);
  box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.18);
}

.sidebar-footer {
  padding-top: 12px;
  border-top: 1px solid var(--border-light);
}

.gcal-mini-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  transition: border-color 0.15s;
}

.gcal-mini-card:hover {
  border-color: var(--primary);
}

.gcal-mini-top {
  display: flex;
  align-items: center;
  gap: 7px;
  font-weight: 600;
  font-size: 12.5px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #94a3b8;
}

.status-dot.online {
  background: var(--success);
}

.gcal-mini-sub {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ==================== MAIN AREA & TOPBAR ==================== */
.main-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-shrink: 0;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 18px;
  min-width: 0;
}

.page-title {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.date-controls {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 4px 6px;
  border-radius: 10px;
}

.btn-today {
  border: none;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 5px 10px;
  border-radius: 7px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
}

.btn-today:hover {
  background: var(--primary-soft);
  border-color: #bfdbfe;
  color: var(--primary);
}

.date-display {
  position: relative;
  padding: 5px 10px;
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  border-radius: 7px;
  text-transform: capitalize;
  white-space: nowrap;
}

.date-display:hover {
  background: var(--hover-bg);
}

.date-input-hidden {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* ==================== BUTTONS ==================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 14px;
  border-radius: 9px;
  font-weight: 600;
  font-size: 13px;
  border: 1px solid transparent;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.25);
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

.btn-secondary:hover {
  background: var(--surface-2);
  border-color: #cbd5e1;
}

.btn-danger-outline {
  background: transparent;
  border-color: var(--danger-border);
  color: var(--danger);
}

.btn-danger-outline:hover {
  background: var(--danger-bg);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 18px;
  transition: all 0.15s ease;
}

.icon-btn:hover {
  background: var(--hover-bg);
  color: var(--text);
}

.theme-toggle-btn {
  border-color: var(--border);
  background: var(--surface-2);
}

/* ==================== VIEWS ==================== */
.view {
  display: none;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 22px;
}

.view.active {
  display: flex;
  flex-direction: column;
}

#view-planning.active {
  overflow: hidden;
  padding-bottom: 14px;
}

/* ==================== TOOLBAR & FILTERS ==================== */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.domain-pills {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}

.domain-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  transition: all 0.15s ease;
}

.domain-pill:hover {
  border-color: #cbd5e1;
  color: var(--text);
}

.domain-pill.active {
  background: var(--pill-active-bg);
  color: var(--pill-active-text);
  border-color: var(--pill-active-bg);
}

.domain-pill .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.domain-pill .count {
  font-size: 11px;
  opacity: 0.75;
}

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 6px 11px;
  width: 240px;
}

.search-box svg {
  color: var(--text-muted);
  flex-shrink: 0;
}

.search-box input {
  border: none;
  outline: none;
  background: transparent;
  width: 100%;
  font-size: 13px;
}

.mobile-view-switch {
  display: none;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 3px;
  border-radius: 9px;
  gap: 3px;
}

.seg-btn {
  border: none;
  background: transparent;
  padding: 6px 10px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  flex: 1;
}

.seg-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* ==================== KPI STRIP ==================== */
.kpi-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 14px;
  flex-shrink: 0;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 15px;
  box-shadow: var(--shadow-sm);
}

.kpi-label {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.kpi-value {
  font-size: 20px;
  font-weight: 700;
  margin-top: 3px;
  letter-spacing: -0.02em;
}

.kpi-sync-val.online {
  color: var(--success);
}

/* ==================== TIMELINE GRID (DESKTOP) ==================== */
.timeline-wrapper {
  flex: 1;
  min-height: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.timeline-scroll {
  flex: 1;
  overflow: auto;
  position: relative;
}

.timeline-grid {
  min-width: calc(var(--sub-col-w) + 14 * var(--hour-w));
  position: relative;
}

.tl-header {
  display: flex;
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

.tl-corner {
  width: var(--sub-col-w);
  flex-shrink: 0;
  position: sticky;
  left: 0;
  z-index: 25;
  background: var(--surface-2);
  border-right: 1px solid var(--border);
  padding: 11px 14px;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  display: flex;
  align-items: center;
}

.tl-hours {
  display: flex;
  flex: 1;
  min-width: calc(14 * var(--hour-w));
}

.tl-hour-head {
  flex: 1 0 var(--hour-w);
  min-width: var(--hour-w);
  padding: 10px 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  border-right: 1px solid var(--border-light);
  text-align: left;
}

.tl-row {
  display: flex;
  border-bottom: 1px solid var(--border-light);
  min-height: var(--row-h);
}

.tl-row:last-child {
  border-bottom: none;
}

.tl-sub-cell {
  width: var(--sub-col-w);
  flex-shrink: 0;
  position: sticky;
  left: 0;
  z-index: 12;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.sub-avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sub-info {
  min-width: 0;
  flex: 1;
}

.sub-name {
  font-weight: 600;
  font-size: 13.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sub-meta {
  font-size: 11.5px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sub-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}

.domain-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10.5px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 999px;
}

.tl-track {
  position: relative;
  display: flex;
  flex: 1;
  min-width: calc(14 * var(--hour-w));
}

.tl-cell {
  flex: 1 0 var(--hour-w);
  min-width: var(--hour-w);
  border-right: 1px solid var(--border-light);
  position: relative;
  cursor: pointer;
  transition: background 0.12s ease;
}

.tl-cell::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  border-left: 1px dashed var(--grid-dash);
  pointer-events: none;
}

.tl-cell:hover {
  background: var(--surface-2);
}

.tl-cell:hover::before {
  content: '+ ' attr(data-hour);
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--primary);
  opacity: 0.7;
  pointer-events: none;
}

.now-line {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: #ef4444;
  z-index: 8;
  pointer-events: none;
}

.now-line::before {
  content: '';
  position: absolute;
  top: -4px;
  left: -4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #ef4444;
}

/* Slot Block */
.slot-block {
  position: absolute;
  top: 7px;
  bottom: 7px;
  border-radius: 9px;
  padding: 6px 9px;
  border-left: 4px solid var(--primary);
  background: #eff6ff;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.07);
  cursor: pointer;
  overflow: hidden;
  z-index: 5;
  display: flex;
  flex-direction: column;
  justify-content: center;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.slot-block:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 14px rgba(15, 23, 42, 0.13);
  z-index: 9;
}

.slot-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  font-size: 11px;
  font-weight: 700;
}

.slot-title {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}

.slot-sub {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.slot-status-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  font-weight: 600;
}

.gcal-synced-icon {
  display: inline-flex;
  color: var(--success);
  flex-shrink: 0;
}

/* ==================== MOBILE CARDS VIEW ==================== */
.mobile-cards-container {
  display: none;
  flex: 1;
  min-height: 0;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  padding-bottom: 84px;
}

.m-sub-card {
  flex-shrink: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.m-sub-head {
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border-light);
}

.m-sub-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.m-call-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: #ecfdf5;
  color: #059669;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.m-add-btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--primary);
  font-weight: 600;
  font-size: 12px;
  padding: 5px 9px;
  border-radius: 8px;
}

.m-slots-list {
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.m-slot-item {
  display: flex;
  gap: 10px;
  padding: 10px 11px;
  border-radius: 10px;
  border-left: 4px solid var(--primary);
  background: var(--surface-2);
  cursor: pointer;
}

.m-slot-time {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  min-width: 52px;
  display: flex;
  flex-direction: column;
}

.m-slot-time span:last-child {
  font-weight: 500;
  color: var(--text-muted);
  font-size: 11px;
}

.m-slot-body {
  flex: 1;
  min-width: 0;
}

.m-empty-slot {
  font-size: 12.5px;
  color: var(--text-muted);
  text-align: center;
  padding: 8px 0;
}

/* ==================== MANAGEMENT VIEWS ==================== */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.section-header h2 {
  font-size: 19px;
  font-weight: 700;
}

.muted {
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 2px;
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 14px;
}

.entity-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.entity-card.inactive {
  opacity: 0.6;
}

.entity-top {
  display: flex;
  align-items: center;
  gap: 12px;
}

.entity-title {
  font-weight: 700;
  font-size: 15px;
}

.entity-sub {
  font-size: 12.5px;
  color: var(--text-muted);
}

.entity-details {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12.5px;
  color: var(--text-muted);
}

.entity-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 10px;
  border-top: 1px solid var(--border-light);
}

/* ==================== GOOGLE CALENDAR VIEW ==================== */
.google-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-sm);
}

.panel.full-span {
  grid-column: 1 / -1;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.panel-header h3 {
  font-size: 15px;
  font-weight: 700;
}

.pill {
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
}

.pill.online {
  background: var(--success-bg);
  color: var(--success);
}

.info-row {
  display: flex;
  justify-content: space-between;
  padding: 9px 0;
  border-bottom: 1px solid var(--border-light);
  font-size: 13px;
}

.gcal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.sync-logs {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 220px;
  overflow-y: auto;
}

.log-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--surface-2);
  font-size: 12.5px;
}

.log-item.error {
  background: var(--danger-bg);
  color: var(--danger);
}

/* ==================== FORMS & MODALS ==================== */
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.48);
  backdrop-filter: blur(2px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}

.modal-backdrop.open {
  display: flex;
}

.modal {
  background: var(--surface);
  border-radius: 16px;
  width: 100%;
  max-width: 540px;
  max-height: 90%;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.modal.modal-sm {
  max-width: 400px;
}

.modal-header {
  padding: 15px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  font-size: 16px;
  font-weight: 700;
}

.modal-body {
  padding: 18px 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 13px;
}

.modal-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--border-light);
}

.spacer {
  flex: 1;
}

.form-stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.form-input {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  outline: none;
  transition: border-color 0.15s;
}

.form-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.color-input {
  height: 40px;
  padding: 4px;
}

.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.form-row-3 {
  display: grid;
  grid-template-columns: 1.3fr 1fr 1fr;
  gap: 10px;
}

.inline-row {
  display: flex;
  gap: 8px;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
}

.domain-checkboxes {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.domain-check-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
}

.domain-check-pill input:checked + span {
  font-weight: 700;
}

.sync-badge-box {
  padding: 9px 11px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border-light);
  font-size: 12.5px;
  color: var(--text-muted);
}

/* ==================== MOBILE NAV & FAB (hidden on desktop) ==================== */
.mobile-bottom-nav,
.fab {
  display: none;
}

/* ==================== TOASTS ==================== */
.toast-container {
  position: absolute;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
}

.toast {
  background: #0f172a;
  color: #fff;
  padding: 10px 15px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  animation: toastIn 0.2s ease;
}

.toast.error {
  background: var(--danger);
}

.toast.success {
  background: #15803d;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.spinning {
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ==================== SHARED MOBILE LAYOUT RULES ==================== */
body.mode-mobile .sidebar { display: none; }
body.mode-mobile .page-title { display: none; }
body.mode-mobile .hide-mobile-text { display: none; }
body.mode-mobile .topbar { padding-left: 12px; padding-right: 12px; padding-bottom: 10px; gap: 8px; }
body.mode-mobile .topbar-left { flex: 1; gap: 6px; }
body.mode-mobile .date-controls { width: 100%; justify-content: space-between; }
body.mode-mobile .btn-today { display: none; }
body.mode-mobile .date-display { font-size: 12.5px; padding: 4px 6px; }
body.mode-mobile #btn-new-slot { display: none; }
body.mode-mobile .view { padding: 12px 12px 80px; }
body.mode-mobile #view-planning.active { padding-bottom: 68px; }
body.mode-mobile .toolbar { gap: 8px; margin-bottom: 10px; }
body.mode-mobile .domain-pills { flex-wrap: nowrap; overflow-x: auto; width: 100%; padding-bottom: 2px; scrollbar-width: none; }
body.mode-mobile .domain-pills::-webkit-scrollbar { display: none; }
body.mode-mobile .domain-pill { flex-shrink: 0; padding: 5px 10px; font-size: 12px; }
body.mode-mobile .toolbar-right { width: 100%; flex-direction: column; align-items: stretch; gap: 8px; }
body.mode-mobile .search-box { width: 100%; }
body.mode-mobile .mobile-view-switch { display: flex; }
body.mode-mobile .kpi-strip { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 5px; margin-bottom: 8px; }
body.mode-mobile .kpi-card { min-width: 0; padding: 7px 4px; text-align: center; }
body.mode-mobile .kpi-label { font-size: 9px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
body.mode-mobile .kpi-value { font-size: 13px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
body.mode-mobile .google-layout { grid-template-columns: 1fr; }
body.mode-mobile .form-row-2,
body.mode-mobile .form-row-3 { grid-template-columns: 1fr; }
body.mode-mobile .modal-backdrop { align-items: flex-end; padding: 0; }
body.mode-mobile .modal { border-radius: 20px 20px 0 0; max-height: 88%; }
body.mode-mobile .toast-container { left: 12px; right: 12px; bottom: 76px; }

body.mode-mobile .mobile-bottom-nav {
  display: flex;
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 62px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 40;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

body.mode-mobile .mb-item {
  flex: 1;
  border: none;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text-muted);
  font-size: 10.5px;
  font-weight: 600;
}

body.mode-mobile .mb-item.active {
  color: var(--primary);
}

body.mode-mobile .fab {
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  right: 16px;
  bottom: 76px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: #fff;
  box-shadow: 0 8px 22px rgba(37, 99, 235, 0.42);
  z-index: 45;
}

/* Mobile sub-views toggling */
body.mode-mobile.mobile-subview-cards .timeline-wrapper { display: none; }
body.mode-mobile.mobile-subview-cards .mobile-cards-container { display: flex; }
body.mode-mobile.mobile-subview-timeline .timeline-wrapper { display: flex; }
body.mode-mobile.mobile-subview-timeline .mobile-cards-container { display: none; }
body.mode-mobile.mobile-subview-timeline {
  --sub-col-w: 116px;
  --hour-w: 76px;
  --row-h: 82px;
}
body.mode-mobile.mobile-subview-timeline .tl-corner { font-size: 10px; padding: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
body.mode-mobile.mobile-subview-timeline .tl-sub-cell { padding: 6px 8px; gap: 6px; }
body.mode-mobile.mobile-subview-timeline .sub-avatar { width: 26px; height: 26px; font-size: 10.5px; border-radius: 7px; }
body.mode-mobile.mobile-subview-timeline .sub-name { font-size: 11.5px; }
body.mode-mobile.mobile-subview-timeline .sub-meta { display: none; }
body.mode-mobile.mobile-subview-timeline .domain-tag { font-size: 9px; padding: 1px 4px; }
body.mode-mobile.mobile-subview-timeline .slot-block { padding: 4px 6px; }
body.mode-mobile.mobile-subview-timeline .slot-top { font-size: 10px; }
body.mode-mobile.mobile-subview-timeline .slot-title { font-size: 11px; }
body.mode-mobile.mobile-subview-timeline .slot-sub { font-size: 10px; }

/* Real mobile screens (auto-switch without phone bezel) */
@media (max-width: 768px) {
  .preview-bar { display: none; }
  .app-frame {
    height: 100dvh !important;
    width: 100% !important;
    margin: 0 !important;
    border: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
  }
  .phone-notch { display: none !important; }
  body.mode-mobile .topbar { padding-top: 10px; }
}
