:root {
  --bg: #f5f6fc;
  --surface: #ffffff;
  --text: #14162b;
  --text-muted: #6b7094;
  --border: #e7e8f5;

  --primary: #4f46e5;
  --primary-dark: #3f37c9;
  --primary-light: #eef0fd;

  --teal: #06b6d4;
  --success: #16a34a;
  --success-light: #e7f9ee;
  --warning: #f59e0b;
  --warning-light: #fef6e6;
  --danger: #ef4444;
  --danger-light: #fdecec;
  --info: #3b82f6;
  --info-light: #eaf2fe;
  --hold: #6b7094;
  --hold-light: #eceef7;

  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(20, 22, 43, 0.06), 0 8px 24px rgba(20, 22, 43, 0.06);
  --shadow-sm: 0 1px 2px rgba(20, 22, 43, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

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

h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 0.5em 0; }
h1 { font-size: 1.75rem; font-weight: 800; }
h2 { font-size: 1.3rem; font-weight: 700; }
h3 { font-size: 1.05rem; font-weight: 700; }

.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 20px 64px;
}

/* ---------- Top nav ---------- */
.topnav {
  background: linear-gradient(100deg, var(--primary) 0%, #6d5df0 60%, var(--teal) 130%);
  color: white;
  box-shadow: var(--shadow);
}
.topnav-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 14px 20px;
  flex-wrap: wrap;
}
.brand {
  font-weight: 800;
  font-size: 1.25rem;
  color: white;
  display: flex;
  align-items: center;
  gap: 8px;
  letter-spacing: -0.02em;
}
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: #ffd43b; display: inline-block; }
.brand-logo { width: 26px; height: 26px; border-radius: 8px; display: block; }
.nav-links { display: flex; gap: 4px; flex-wrap: wrap; margin-left: 8px; }
.nav-links a {
  color: rgba(255,255,255,0.88);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.92rem;
}
.nav-links a:hover, .nav-links a.active {
  background: rgba(255,255,255,0.16);
  color: white;
  text-decoration: none;
}
.nav-spacer { flex: 1; }
.nav-user {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
}
.nav-user form { margin: 0; }
.btn-logout {
  background: rgba(255,255,255,0.16);
  color: white;
  border: none;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  cursor: pointer;
  font-size: 0.88rem;
}
.btn-logout:hover { background: rgba(255,255,255,0.28); }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  margin-bottom: 20px;
}
.card-flat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

/* ---------- Stat cards ---------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  color: white;
  position: relative;
  overflow: hidden;
}
.stat-card .stat-value { font-size: 2.2rem; font-weight: 800; }
.stat-card .stat-label { font-size: 0.92rem; opacity: 0.92; font-weight: 600; margin-top: 2px; }
.stat-pending { background: linear-gradient(135deg, #f59e0b, #f7b733); }
.stat-progress { background: linear-gradient(135deg, #3b82f6, #6dd5fa); }
.stat-overdue { background: linear-gradient(135deg, #ef4444, #ff7a7a); }
.stat-served { background: linear-gradient(135deg, #16a34a, #4ade80); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--primary);
  color: white;
  border: none;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  transition: transform 0.05s ease, background 0.15s ease;
}
.btn:hover { background: var(--primary-dark); text-decoration: none; }
.btn:active { transform: scale(0.98); }
.btn-secondary { background: var(--primary-light); color: var(--primary-dark); }
.btn-secondary:hover { background: #e0e2fb; }
.btn-success { background: var(--success); }
.btn-success:hover { background: #128a3e; }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #d63636; }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg); }
.btn-sm { padding: 6px 12px; font-size: 0.85rem; }
.btn-block { width: 100%; justify-content: center; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- Forms ---------- */
label { display: block; font-weight: 700; font-size: 0.88rem; margin-bottom: 6px; color: var(--text); }
.field { margin-bottom: 16px; }
.field-hint { color: var(--text-muted); font-size: 0.82rem; margin-top: 4px; }
input[type=text], input[type=email], input[type=password], input[type=date],
input[type=tel], input[type=number], input[type=search], input[type=datetime-local],
select, textarea {
  width: 100%;
  padding: 11px 13px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  /* 16px minimum keeps iOS Safari from auto-zooming the page when a field
     is focused - important since this form is filled out on phones in the field. */
  font-size: 1rem;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}
textarea { resize: vertical; min-height: 80px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
@media (max-width: 640px) {
  .form-grid, .form-grid-3 { grid-template-columns: 1fr; }
}
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: 20px; height: 20px; flex-shrink: 0; }
.checkbox-row label { margin: 0; font-weight: 600; }

.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 18px;
  font-weight: 600;
  font-size: 0.92rem;
}
.alert-danger { background: var(--danger-light); color: #b42323; }
.alert-success { background: var(--success-light); color: #0f6b2c; }
.alert-warning { background: var(--warning-light); color: #92610a; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.badge-pending, .badge-assigned { background: var(--warning-light); color: #92610a; }
.badge-in_progress { background: var(--info-light); color: #1d4ed8; }
.badge-served { background: var(--success-light); color: #0f6b2c; }
.badge-non_served { background: var(--danger-light); color: #b42323; }
.badge-held, .badge-cancelled { background: var(--hold-light); color: var(--hold); }
.badge-rush { background: #fff0e0; color: #b5590a; }
.badge-same_day { background: var(--danger-light); color: #b42323; }
.badge-routine { background: var(--hold-light); color: var(--hold); }

/* ---------- Tables / lists ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-muted); padding: 10px 14px; border-bottom: 2px solid var(--border); }
td { padding: 13px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }

/* On a narrow phone screen, a wide data table just gets clipped or needs
   sideways scrolling to see the Status/Server/Priority columns - not great
   for a quick glance in the field. Below this width, each row becomes a
   stacked card instead: the first column (the job's headline) stays as a
   card title, and the rest render as "Label: value" lines via data-label. */
@media (max-width: 700px) {
  .table-wrap table, .table-wrap tbody, .table-wrap tr, .table-wrap td { display: block; width: 100%; }
  .table-wrap thead { display: none; }
  .table-wrap tr {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 10px;
    padding: 12px 14px;
  }
  .table-wrap td { border-bottom: none; padding: 4px 0; }
  .table-wrap td:first-child { font-size: 1.05rem; padding-top: 0; }
  .table-wrap td:not(:first-child) { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
  .table-wrap td:not(:first-child)::before {
    content: attr(data-label);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-muted);
    font-weight: 700;
  }
}
tr:last-child td { border-bottom: none; }
.row-link { display: block; }
tbody tr:hover { background: var(--primary-light); }

.list-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  margin-bottom: 10px;
  background: var(--surface);
}
.list-row:hover { border-color: var(--primary); box-shadow: var(--shadow-sm); }

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}

.toolbar { display: flex; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 18px; flex-wrap: wrap; }
.toolbar-filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.chip {
  padding: 7px 14px;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--text-muted);
  background: var(--surface);
}
.chip.active { background: var(--primary); color: white; border-color: var(--primary); }

.detail-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; }
@media (max-width: 860px) { .detail-grid { grid-template-columns: 1fr; } }

.kv { margin-bottom: 12px; }
.kv .k { font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-muted); font-weight: 700; }
.kv .v { font-size: 1rem; font-weight: 600; }

.timeline-item { border-left: 3px solid var(--primary-light); padding: 4px 0 4px 16px; margin-bottom: 14px; position: relative; }
.timeline-item::before { content: ""; position: absolute; left: -7px; top: 8px; width: 11px; height: 11px; border-radius: 50%; background: var(--primary); }
.timeline-item.outcome-served::before { background: var(--success); }
.timeline-item.outcome-unsuccessful_attempt::before { background: var(--warning); }
.timeline-item.outcome-non_served::before { background: var(--danger); }

.photo-thumb { max-width: 220px; border-radius: var(--radius-sm); margin-top: 8px; box-shadow: var(--shadow-sm); }

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

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary) 0%, #6d5df0 55%, var(--teal) 130%);
  padding: 20px;
}
.login-card {
  background: white;
  border-radius: 20px;
  padding: 40px 36px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(20,22,43,0.25);
}
.login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
  margin-bottom: 24px;
  font-weight: 800;
  font-size: 1.5rem;
  color: var(--primary);
}
.login-brand .dot { color: var(--teal); }
.login-logo { width: 52px; height: 52px; border-radius: 14px; box-shadow: var(--shadow-sm); }

footer.app-footer {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.82rem;
  padding: 24px;
}
