/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --color-primary:    #1a56db;
  --color-success:    #057a55;
  --color-danger:     #c81e1e;
  --color-warning:    #c27803;
  --color-secondary:  #6b7280;
  --color-bg:         #f9fafb;
  --color-surface:    #ffffff;
  --color-border:     #e5e7eb;
  --color-text:       #111827;
  --color-text-muted: #6b7280;
  /* Call status colours — must match the pantry touch panels: blue for a new
     call, green once acknowledged. Keyed to the calls.status CHECK constraint
     in src/config/db.js (new | acknowledged | cleared) — add a token here for
     any status added there, or the card/badge silently renders unstyled. */
  --color-call-new:          var(--color-primary);
  --color-call-acknowledged: var(--color-success);
  --color-call-cleared:      var(--color-secondary);
  --radius:           8px;
  --shadow:           0 1px 3px rgba(0,0,0,.1);
  --shadow-md:        0 4px 12px rgba(0,0,0,.12);
}

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

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== Navbar ===== */
.navbar {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}
.navbar-brand a {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--color-primary);
  text-decoration: none;
  letter-spacing: -0.3px;
}
.navbar-links {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}
.navbar-links a {
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius);
  color: var(--color-text);
  font-size: 0.9rem;
  text-decoration: none;
  transition: background 0.15s;
}
.navbar-links a:hover, .navbar-links a.active { background: var(--color-bg); }
.btn-link {
  background: none; border: none; cursor: pointer;
  color: var(--color-text-muted); font-size: 0.9rem;
  padding: 0.4rem 0.75rem; border-radius: var(--radius);
}
.btn-link:hover { background: var(--color-bg); color: var(--color-text); }

/* ===== Owner Location Sub-Nav ===== */
.location-subnav {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 0 1.5rem;
  position: sticky;
  top: 56px;
  z-index: 99;
  box-shadow: 0 1px 2px rgba(0,0,0,.06);
}
.location-subnav-inner {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  height: 44px;
}
.subnav-back {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  text-decoration: none;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius);
  white-space: nowrap;
  flex-shrink: 0;
}
.subnav-back:hover { background: var(--color-bg); color: var(--color-text); text-decoration: none; }
.location-switcher { flex-shrink: 0; }
.location-switcher select {
  width: auto;
  padding: 0.25rem 0.5rem;
  font-size: 0.875rem;
  font-weight: 600;
  border-color: var(--color-border);
  cursor: pointer;
}
.subnav-links {
  display: flex;
  align-items: center;
  gap: 0.125rem;
  border-left: 1px solid var(--color-border);
  padding-left: 0.75rem;
  margin-left: 0.25rem;
}
.subnav-links a {
  padding: 0.3rem 0.65rem;
  font-size: 0.85rem;
  color: var(--color-text-muted);
  border-radius: var(--radius);
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}
.subnav-links a:hover { background: var(--color-bg); color: var(--color-text); }
.subnav-links a.active { background: var(--color-bg); color: var(--color-primary); font-weight: 600; }

/* ===== Container ===== */
.container { max-width: 1100px; margin: 0 auto; padding: 2rem 1.5rem; }

/* ===== Login ===== */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 2.5rem;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-md);
}
.login-logo { text-align: center; margin-bottom: 2rem; }
.login-logo h1 { font-size: 1.75rem; color: var(--color-primary); }
.login-logo p { color: var(--color-text-muted); margin-top: 0.25rem; }

/* ===== Forms ===== */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-weight: 500; font-size: 0.875rem; margin-bottom: 0.375rem; }
input[type="text"], input[type="email"], input[type="password"], select, textarea {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  background: var(--color-surface);
  color: var(--color-text);
  transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(26,86,219,0.1);
}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-group-full { grid-column: 1 / -1; }

/* Optional settings most people should leave alone, collapsed so they are not mistaken for required ones. */
.form-advanced { border: 1px dashed var(--color-border); border-radius: var(--radius); padding: 0.75rem 1rem; }
.form-advanced summary { cursor: pointer; font-weight: 500; }
.form-advanced[open] summary { margin-bottom: 0.75rem; }
.form-advanced input { margin-top: 0.25rem; }
.form-hint--warning { color: var(--color-warning); }
.form-inline { display: flex; gap: 0.75rem; align-items: flex-end; flex-wrap: wrap; }
.form-inline input, .form-inline select { flex: 1; min-width: 150px; }
.filter-form { display: flex; gap: 0.5rem; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; gap: 0.375rem;
  padding: 0.5rem 1rem; border: none; border-radius: var(--radius);
  font-size: 0.875rem; font-weight: 500; cursor: pointer;
  text-decoration: none; transition: opacity 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.98); }
.btn:hover { opacity: 0.88; }
.btn-primary   { background: var(--color-primary);   color: #fff; }
.btn-success   { background: var(--color-success);   color: #fff; }
.btn-danger    { background: var(--color-danger);     color: #fff; }
.btn-secondary { background: var(--color-secondary); color: #fff; }

/* Account invitation / activation */
.checkbox-label { display: flex; align-items: center; gap: 0.5rem; font-weight: 500; cursor: pointer; }
.checkbox-label input { width: auto; margin: 0; }
.form-hint { margin: 0.375rem 0 0; font-size: 0.875rem; color: var(--color-text-muted); }
.activate-intro { margin: 0 0 1.25rem; font-size: 0.9375rem; color: var(--color-text-muted); text-align: center; }
.btn-block { width: 100%; justify-content: center; padding: 0.625rem 1rem; }
.btn-sm  { padding: 0.3rem 0.6rem; font-size: 0.8rem; }
.btn-xs  { padding: 0.2rem 0.4rem; font-size: 0.75rem; }

/* ===== Alerts ===== */
.alert { padding: 0.75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: 0.9rem; }
.alert-error   { background: #fde8e8; color: var(--color-danger); border: 1px solid #fbd5d5; }
.alert-success { background: #def7ec; color: #03543f; border: 1px solid #bcf0da; }
.alert-info    { background: #e1effe; color: #1e429f; border: 1px solid #bfdbfe; }
.alert-warning { background: #fdf6b2; color: #8e4b10; border: 1px solid #fce96a; }

/* A single-column form reads badly at full page width. */
.section-narrow { max-width: 28rem; }

/* ===== Page Header ===== */
.page-header { margin-bottom: 1.5rem; display: flex; align-items: center; gap: 1rem; }
.page-header h2 { font-size: 1.5rem; font-weight: 700; }
.page-location { font-size: 1rem; font-weight: 400; color: var(--color-text-muted); }
.subtitle { color: var(--color-text-muted); }

/* ===== Sections ===== */
.section { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); padding: 1.5rem; margin-bottom: 1.5rem; }
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.section-header h3 { font-size: 1rem; font-weight: 600; }

/* ===== Tables ===== */
.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table th { text-align: left; padding: 0.625rem 0.75rem; border-bottom: 2px solid var(--color-border); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--color-text-muted); }
.table td { padding: 0.625rem 0.75rem; border-bottom: 1px solid var(--color-border); }
.table tr:last-child td { border-bottom: none; }
.table-striped tr:nth-child(even) td { background: var(--color-bg); }
.empty { color: var(--color-text-muted); font-style: italic; padding: 1rem 0; }

/* ===== Stats Grid ===== */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); padding: 1.25rem; text-align: center; }
.stat-number { font-size: 2rem; font-weight: 700; color: var(--color-primary); line-height: 1; }
#newCount          { color: var(--color-call-new); }
#acknowledgedCount { color: var(--color-call-acknowledged); }
.stat-label { font-size: 0.8rem; color: var(--color-text-muted); margin-top: 0.25rem; text-transform: uppercase; letter-spacing: 0.05em; }

/* ===== Badges ===== */
.badge {
  display: inline-block; padding: 0.2rem 0.5rem; border-radius: 20px;
  font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em;
}
.badge-yacht    { background: #e0f2fe; color: #075985; }
.badge-home     { background: #f0fdf4; color: #166534; }
.badge-active   { background: #f0fdf4; color: #166534; }
.badge-inactive { background: #f3f4f6; color: var(--color-text-muted); }
.badge-new          { background: #dbeafe; color: #1e40af; }
.badge-acknowledged { background: #d1fae5; color: #065f46; }
.badge-cleared      { background: #f3f4f6; color: var(--color-text-muted); }
.badge-pushover { background: #fee2e2; color: #991b1b; }
.badge-apns     { background: #e0f2fe; color: #075985; }
.badge-webpush  { background: #ede9fe; color: #4c1d95; }

/* ===== Calls Grid ===== */
.calls-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
.empty-calls { text-align: center; padding: 3rem; color: var(--color-text-muted); background: var(--color-surface); border-radius: var(--radius); border: 2px dashed var(--color-border); }

.call-card {
  background: var(--color-surface);
  border: 2px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
  transition: box-shadow 0.2s;
}
.call-card:hover { box-shadow: var(--shadow-md); }
/* The call a push notification linked through to */
.call-card--linked { box-shadow: 0 0 0 2px var(--color-primary), var(--shadow-md); }
.call-card--new          { border-left: 4px solid var(--color-call-new); }
.call-card--acknowledged { border-left: 4px solid var(--color-call-acknowledged); }
.call-card--cleared      { border-left: 4px solid var(--color-call-cleared); }

.call-card__header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.75rem; }
.call-time { font-size: 0.8rem; color: var(--color-text-muted); }

.call-badge { display: inline-block; padding: 0.2rem 0.5rem; border-radius: 20px; font-size: 0.75rem; font-weight: 700; text-transform: uppercase; }
.call-badge--new          { background: #dbeafe; color: #1e40af; }
.call-badge--acknowledged { background: #d1fae5; color: #065f46; }
.call-badge--cleared      { background: #f3f4f6; color: var(--color-text-muted); }

.call-card__body { display: flex; flex-direction: column; gap: 0.375rem; }
.call-field { display: flex; gap: 0.5rem; font-size: 0.875rem; }
.call-label { font-weight: 600; min-width: 60px; color: var(--color-text-muted); }
.call-value { color: var(--color-text); }

.call-card__actions { display: flex; gap: 0.5rem; margin-top: 1rem; padding-top: 0.75rem; border-top: 1px solid var(--color-border); }

/* ===== Live Indicator ===== */
.live-indicator {
  background: #d1fae5; color: #065f46;
  padding: 0.2rem 0.6rem; border-radius: 20px;
  font-size: 0.75rem; font-weight: 700;
  display: flex; align-items: center; gap: 0.3rem;
}
.live-indicator::before {
  content: '';
  width: 6px; height: 6px;
  background: #059669;
  border-radius: 50%;
  animation: pulse 2s infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

/* Set by public/js/app.js when polling fails, so a stale list cannot pass for a live one. */
.live-indicator--reconnecting { background: #fdf6b2; color: #8e4b10; }
.live-indicator--reconnecting::before { background: #c27803; }
.live-indicator--offline { background: #fde8e8; color: var(--color-danger); }
.live-indicator--offline::before { background: var(--color-danger); animation: none; }

/* ===== Service Grid ===== */
.service-grid { display: flex; flex-wrap: wrap; gap: 0.75rem; }
.service-card {
  background: var(--color-bg); border: 1px solid var(--color-border);
  border-radius: var(--radius); padding: 0.5rem 0.75rem;
  display: flex; align-items: center; gap: 0.5rem; font-size: 0.9rem;
}
.service-icon { font-size: 1.25rem; }

/* ===== Responsive ===== */
@media (max-width: 640px) {
  .container { padding: 1rem; }
  .form-grid { grid-template-columns: 1fr; }
  .form-inline { flex-direction: column; }
  .navbar-links a span { display: none; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .calls-grid { grid-template-columns: 1fr; }
  .table th:nth-child(n+4), .table td:nth-child(n+4) { display: none; }
}
