@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&family=Inter:wght@400;500;600&family=IBM+Plex+Mono:wght@400;500&display=swap');

:root {
  --bg: #0d1520;
  --panel: #141f2e;
  --panel-alt: #182231;
  --border: #24334a;
  --accent: #3ea8a0;
  --accent-soft: rgba(62,168,160,0.14);
  --amber: #d99a3d;
  --amber-soft: rgba(217,154,61,0.14);
  --danger: #c9695b;
  --danger-soft: rgba(201,105,91,0.14);
  --text: #e6ebf0;
  --text-muted: #8697ac;
  --text-dim: #5c6b7f;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: 'Inter', sans-serif;
  color: var(--text);
  background:
    linear-gradient(var(--bg), var(--bg)),
    repeating-linear-gradient(0deg, rgba(255,255,255,0.025) 0px, rgba(255,255,255,0.025) 1px, transparent 1px, transparent 32px),
    repeating-linear-gradient(90deg, rgba(255,255,255,0.025) 0px, rgba(255,255,255,0.025) 1px, transparent 1px, transparent 32px);
  min-height: 100vh;
  font-size: 14px;
  overscroll-behavior-y: contain;
}
h1, h2, h3 { font-family: 'Space Grotesk', sans-serif; margin: 0; letter-spacing: -0.01em; }
.mono { font-family: 'IBM Plex Mono', monospace; }
button { font-family: 'Inter', sans-serif; cursor: pointer; touch-action: manipulation; }
a, .navitem, .list-row, .alertrow, .list-row, .btn, .iconbtn, .logout-link { touch-action: manipulation; }

/* ---------- Login ---------- */
#login-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
}
.login-box {
  background: var(--panel); border: 1px solid var(--border); border-radius: 6px;
  padding: 34px 32px; width: 340px; max-width: 90vw;
}
.login-brand { margin-bottom: 22px; }
.login-brand-title { font-size: 18px; font-weight: 600; }
.login-brand-sub { color: var(--text-dim); font-size: 11px; margin-top: 4px; font-family: 'IBM Plex Mono', monospace; }
.login-error { color: var(--danger); font-size: 12.5px; margin-top: 10px; min-height: 16px; }

/* ---------- App shell ---------- */
#app-screen { display: none; min-height: 100vh; }
#app-screen.visible { display: flex; }

.mobile-topbar { display: none; }

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-scroll table { min-width: 480px; }

.sidebar {
  width: 210px; flex-shrink: 0; border-right: 1px solid var(--border);
  padding: 22px 14px; display: flex; flex-direction: column; gap: 22px;
}
.brand { padding: 0 8px; }
.brand-title { font-size: 16px; font-weight: 600; }
.brand-sub { color: var(--text-dim); font-size: 11px; margin-top: 3px; font-family: 'IBM Plex Mono', monospace; }
.navlist { display: flex; flex-direction: column; gap: 3px; }
.navitem {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 3px;
  cursor: pointer; color: var(--text-muted); border: 1px solid transparent;
}
.navitem:hover { background: var(--panel-alt); color: var(--text); }
.navitem.active { background: var(--accent-soft); color: var(--accent); border-color: rgba(62,168,160,0.3); }
.nav-alert-dot {
  margin-left: auto; background: var(--danger); color: #1a0f0d; font-size: 10px; font-weight: 600;
  min-width: 17px; height: 17px; border-radius: 9px; display: flex; align-items: center; justify-content: center;
  font-family: 'IBM Plex Mono', monospace;
}
.sidebar-footer { margin-top: auto; border-top: 1px solid var(--border); padding-top: 14px; }
.session-user { font-size: 12.5px; }
.session-role { color: var(--text-dim); font-size: 11px; font-family: 'IBM Plex Mono', monospace; text-transform: uppercase; }
.logout-link { color: var(--text-dim); font-size: 12px; cursor: pointer; margin-top: 8px; margin-right: 12px; display: inline-block; }
.logout-link:hover { color: var(--text); }

.main { flex: 1; padding: 26px 34px 60px; overflow-x: hidden; max-width: 1180px; }
.topbar { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 22px; flex-wrap: wrap; gap: 10px; }
.topbar .date { color: var(--text-dim); font-family: 'IBM Plex Mono', monospace; font-size: 12px; }

.statgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 24px; }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: 4px; padding: 16px; }
.stat-label { color: var(--text-dim); font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; }
.stat-value { font-family: 'Space Grotesk', sans-serif; font-size: 30px; font-weight: 600; margin-top: 6px; }
.stat.warn .stat-value { color: var(--amber); }
.stat.bad .stat-value { color: var(--danger); }

.section { background: var(--panel); border: 1px solid var(--border); border-radius: 4px; padding: 18px 20px; margin-bottom: 20px; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; flex-wrap: wrap; gap: 8px; }
.section-head h2 { font-size: 14px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }

.alertrow {
  display: grid; grid-template-columns: 20px 1.4fr 1fr 110px 90px; gap: 12px; align-items: center;
  padding: 10px 4px; border-bottom: 1px solid var(--border); cursor: pointer;
}
.alertrow:last-child { border-bottom: none; }
.alertrow:hover { background: var(--panel-alt); }
.alertrow .due { color: var(--text-dim); font-family: 'IBM Plex Mono', monospace; font-size: 12px; }
.alertrow .cust { font-weight: 500; }
.sys-with-icon { color: var(--text-muted); display: flex; align-items: center; gap: 6px; }

.badge { font-family: 'IBM Plex Mono', monospace; font-size: 11px; padding: 3px 8px; border-radius: 3px; white-space: nowrap; display: inline-block; }
.badge-overdue { background: var(--danger-soft); color: var(--danger); }
.badge-due-soon { background: var(--amber-soft); color: var(--amber); }
.badge-ok { background: var(--accent-soft); color: var(--accent); }
.badge-ended { background: var(--panel-alt); color: var(--text-dim); border: 1px solid var(--border); }

.empty { color: var(--text-dim); padding: 30px 0; text-align: center; font-size: 13px; }

.btn {
  font-size: 13px; font-weight: 500; background: var(--accent); color: #08201d; border: none;
  border-radius: 3px; padding: 9px 14px; display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.secondary { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn.secondary:hover { color: var(--text); border-color: var(--text-dim); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid rgba(201,105,91,0.4); }
.btn.ghost { background: transparent; color: var(--accent); padding: 6px 8px; }
.iconbtn { background: transparent; border: none; color: var(--text-dim); padding: 4px; }
.iconbtn:hover { color: var(--text); }

.searchbar { display: flex; align-items: center; gap: 8px; background: var(--panel-alt); border: 1px solid var(--border); border-radius: 3px; padding: 7px 10px; width: 220px; }
.searchbar input { background: transparent; border: none; outline: none; color: var(--text); font-size: 13px; width: 100%; }

.list-row { display: flex; align-items: center; justify-content: space-between; padding: 13px 6px; border-bottom: 1px solid var(--border); cursor: pointer; }
.list-row:hover { background: var(--panel-alt); }
.list-row:last-child { border-bottom: none; }
.list-row .name { font-weight: 500; }
.list-row .meta { color: var(--text-dim); font-size: 12px; margin-top: 2px; }

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; background: var(--panel-alt); border: 1px solid var(--border); border-radius: 3px;
  padding: 8px 10px; color: var(--text); font-family: 'Inter', sans-serif; font-size: 13px; outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.field input:disabled, .field select:disabled { color: var(--text-dim); cursor: not-allowed; opacity: 0.75; }
.fieldrow { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

table.systable { width: 100%; border-collapse: collapse; }
table.systable th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-dim); font-weight: 500; padding: 6px 8px; border-bottom: 1px solid var(--border); }
table.systable td { padding: 10px 8px; border-bottom: 1px solid var(--border); font-size: 13px; }
table.systable tr:last-child td { border-bottom: none; }
.sysname { display: flex; align-items: center; gap: 8px; }

.back { display: flex; align-items: center; gap: 6px; color: var(--text-muted); cursor: pointer; font-size: 13px; margin-bottom: 16px; }
.back:hover { color: var(--text); }

.bar-chart { display: flex; align-items: flex-end; gap: 6px; height: 180px; padding-top: 10px; }
.bar-chart .bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.bar-chart .bar { width: 100%; max-width: 26px; background: var(--accent); border-radius: 2px 2px 0 0; min-height: 2px; }
.bar-chart .bar.over { background: var(--danger); }
.bar-chart .bar-label { color: var(--text-dim); font-size: 10px; margin-top: 6px; font-family: 'IBM Plex Mono', monospace; white-space: nowrap; }
.bar-chart .bar-count { color: var(--text-dim); font-size: 10px; margin-bottom: 4px; font-family: 'IBM Plex Mono', monospace; }

/* ---------- Searchable customer combo (Log a visit / Reports) ---------- */
.combo { position: relative; }
.combo-input-wrap {
  display: flex; align-items: center; gap: 8px; background: var(--panel-alt);
  border: 1px solid var(--border); border-radius: 3px; padding: 8px 10px;
}
.combo-input-wrap:focus-within { border-color: var(--accent); }
.combo-input { flex: 1; background: transparent; border: none; outline: none; color: var(--text); font-family: 'Inter', sans-serif; font-size: 13px; }
.combo-list {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 30;
  background: var(--panel); border: 1px solid var(--border); border-radius: 4px;
  max-height: 240px; overflow-y: auto; box-shadow: 0 8px 24px rgba(0,0,0,0.35);
}
.combo-item { padding: 9px 12px; font-size: 13px; cursor: pointer; }
.combo-item:hover { background: var(--panel-alt); }
.combo-item.selected { color: var(--accent); }
.combo-empty { padding: 12px; color: var(--text-dim); font-size: 12.5px; }

/* ---------- Donut chart ---------- */
.donut-wrap { display: flex; align-items: center; gap: 28px; flex-wrap: wrap; }
.donut-svg svg { display: block; }
.donut-legend { display: flex; flex-direction: column; gap: 8px; flex: 1; min-width: 160px; }
.legend-row { display: flex; align-items: center; gap: 8px; font-size: 12.5px; }
.legend-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.legend-label { color: var(--text-muted); flex: 1; }
.legend-value { color: var(--text); }

/* ---------- Horizontal bar chart (technician workload, cities) ---------- */
.hbar-chart { display: flex; flex-direction: column; gap: 10px; }
.hbar-row { display: grid; grid-template-columns: 120px 1fr 34px; gap: 10px; align-items: center; }
.hbar-label { font-size: 12.5px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar-track { background: var(--panel-alt); border-radius: 2px; height: 10px; overflow: hidden; }
.hbar-fill { height: 100%; background: var(--accent); border-radius: 2px; }
.hbar-value { font-size: 11.5px; color: var(--text-dim); text-align: right; }

/* ---------- Reports tab bar (Overview / By customer) ---------- */
.tabbar { display: flex; gap: 4px; margin-bottom: 18px; border-bottom: 1px solid var(--border); }
.tab { padding: 9px 4px; margin-right: 18px; font-size: 13px; color: var(--text-dim); cursor: pointer; border-bottom: 2px solid transparent; }
.tab:hover { color: var(--text-muted); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.clickable-row { cursor: pointer; }
.clickable-row:hover { background: var(--panel-alt); }

/* ---------- Filter bar (Reports > Overview > Maintenance schedule) ---------- */
.filterbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.filter-input {
  background: var(--panel-alt); border: 1px solid var(--border); border-radius: 3px;
  padding: 8px 10px; color: var(--text); font-family: 'Inter', sans-serif; font-size: 13px;
  width: 180px; max-width: 100%;
}
.filter-input:focus { outline: none; border-color: var(--accent); }
.filter-date-group { display: flex; align-items: center; gap: 6px; }
.filter-date {
  background: var(--panel-alt); border: 1px solid var(--border); border-radius: 3px;
  padding: 7px 8px; color: var(--text); font-family: 'IBM Plex Mono', monospace; font-size: 12.5px;
}
.filter-date-sep { color: var(--text-dim); font-size: 12px; }

.location-inline { display: inline-flex; align-items: center; gap: 3px; }
.location-inline svg { position: relative; top: 1px; }

.roleselect {
  background: var(--panel-alt); border: 1px solid var(--border); border-radius: 3px;
  padding: 4px 6px; color: var(--text); font-family: 'IBM Plex Mono', monospace; font-size: 11.5px;
}

.modal-overlay { position: fixed; inset: 0; background: rgba(6,10,16,0.65); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal-box { background: var(--panel); border: 1px solid var(--border); border-radius: 6px; padding: 20px 22px; width: 420px; max-width: 90vw; max-height: 85vh; overflow-y: auto; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal-head h3 { font-size: 15px; }

.toast { color: var(--accent); font-size: 12.5px; margin-top: 10px; }
.banner-error { color: var(--danger); font-size: 12.5px; margin-bottom: 12px; }

/* =====================================================================
   Mobile — makes the app behave like a native phone app: a fixed top
   bar, a bottom tab bar instead of a side rail, full-width bottom-sheet
   modals, larger tap targets, and no accidental iOS zoom on inputs.
   ===================================================================== */
@media (max-width: 860px) {

  /* Top bar: brand + current user + logout, replaces the sidebar's brand/footer */
  .mobile-topbar {
    display: flex; align-items: center; justify-content: space-between;
    position: fixed; top: 0; left: 0; right: 0; z-index: 45;
    height: 52px; padding: 0 16px; padding-top: env(safe-area-inset-top);
    background: var(--panel); border-bottom: 1px solid var(--border);
  }
  .mobile-topbar-brand { font-family: 'Space Grotesk', sans-serif; font-weight: 600; font-size: 15px; }
  .mobile-topbar-user { display: flex; align-items: center; gap: 12px; font-size: 12px; color: var(--text-dim); }
  .mobile-topbar-user .logout-link { margin-top: 0; }

  /* Sidebar becomes a fixed bottom tab bar; its brand/footer are replaced by the top bar above */
  .sidebar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
    width: 100%; height: auto; flex-direction: row;
    border-right: none; border-top: 1px solid var(--border);
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
    gap: 0; background: var(--panel);
  }
  .sidebar .brand, .sidebar .sidebar-footer { display: none; }
  .navlist { flex-direction: row; width: 100%; gap: 2px; }
  .navitem {
    flex: 1; flex-direction: column; gap: 3px; padding: 7px 2px 6px;
    border-radius: 8px; font-size: 10px; text-align: center;
  }
  .navitem span { white-space: nowrap; }
  .navitem svg { width: 19px; height: 19px; }
  .nav-alert-dot { position: absolute; margin-left: 0; top: 2px; right: 18%; }
  .navitem { position: relative; }

  /* Main content: clear the fixed top/bottom bars, tighter side padding */
  .main {
    padding: calc(52px + env(safe-area-inset-top) + 18px) 16px calc(64px + env(safe-area-inset-bottom) + 20px);
    max-width: 100%;
  }
  .topbar h1 { font-size: 20px; }

  .statgrid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .stat { padding: 12px; }
  .stat-value { font-size: 22px; }

  .section { padding: 14px; }

  .fieldrow { grid-template-columns: 1fr; gap: 0; }
  /* 16px prevents iOS Safari from auto-zooming the page on focus */
  .field input, .field select, .field textarea { font-size: 16px; padding: 10px 12px; }
  .field { margin-bottom: 14px; }

  .searchbar { width: 100%; }

  /* Alerts: drop the redundant date column and let the row wrap instead of clipping */
  .alertrow {
    display: flex; flex-wrap: wrap; align-items: center; gap: 5px 10px;
    padding: 12px 4px;
  }
  .alertrow .due { display: none; }
  .alertrow .cust { flex: 1 1 100%; order: 1; }
  .alertrow .sys-with-icon { order: 2; font-size: 12px; }
  .alertrow .badge { order: 3; margin-left: auto; }

  /* Buttons: comfortable tap targets */
  .btn, .btn.secondary, .btn.danger { min-height: 42px; }
  .btn.ghost { min-height: 34px; }

  /* Bar charts: scroll horizontally instead of squeezing bars unreadably thin */
  .bar-chart { overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 4px; }
  .bar-chart .bar-col { min-width: 32px; }

  /* Modals become a full-width bottom sheet */
  .modal-overlay { align-items: flex-end; }
  .modal-box {
    width: 100%; max-width: 100%; max-height: 88vh;
    border-radius: 14px 14px 0 0;
    padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  }

  .list-row { padding: 14px 4px; }

  /* Donut + horizontal-bar charts: stack instead of squeezing side by side */
  .donut-wrap { flex-direction: column; align-items: flex-start; gap: 16px; }
  .hbar-row { grid-template-columns: 90px 1fr 30px; gap: 8px; }
  .tabbar { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .filterbar { flex-direction: column; align-items: stretch; }
  .filter-input { width: 100%; font-size: 16px; padding: 10px 12px; }
  .filter-date-group { width: 100%; }
  .filter-date { flex: 1; font-size: 16px; padding: 9px 8px; }
}

