/* ── Variables ─────────────────────────────────────────────── */
:root {
  --primary:       #4f46e5;
  --primary-dark:  #4338ca;
  --primary-light: #eef2ff;
  --secondary:       #0ea5e9;
  --secondary-dark:  #0284c7;
  --secondary-light: #e0f2fe;
  --success:       #16a34a;
  --warning:       #d97706;
  --danger:        #dc2626;
  --danger-light:  #fef2f2;

  --text:          #1e293b;
  --text-muted:    #64748b;
  --border:        #e2e8f0;
  --bg:            #f1f5f9;
  --surface:       #ffffff;

  --radius:        0.5rem;
  --radius-lg:     0.75rem;
  --shadow:        0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
  --shadow-sm:     0 1px 2px rgba(0,0,0,.06);

  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;

  --topbar-bg:         var(--surface);
  --topbar-border:     var(--border);
  --topbar-text:       var(--text);
  --topbar-text-muted: var(--text-muted);

  --progress-color: var(--secondary);
  --badge-color:    var(--secondary);
  --client-color:   #7c3aed;
}

/* ── Page transitions ───────────────────────────────────────── */
/* Native cross-document fade in Chrome 126+ / Edge 126+. No JS needed.   */
/* Older browsers ignore this rule and fall back to an instant page load.  */
@view-transition { navigation: auto; }

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

/* Set background on html so the page is never white between navigations. */
html { background: var(--bg); }

@keyframes page-in { from { opacity: 0; } to { opacity: 1; } }

body {
  font-family: var(--font);
  font-size: 0.9375rem;
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
  min-height: 100vh;
  animation: page-in 0.13s ease-out;
}

/* ── Typography ────────────────────────────────────────────── */
h1 { font-size: 1.5rem;    font-weight: 700; line-height: 1.3; }
h2 { font-size: 1.25rem;   font-weight: 600; line-height: 1.3; }
h3 { font-size: 1.0625rem; font-weight: 600; }
p  { color: var(--text-muted); }

/* ── Card ──────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 2rem;
}

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.625rem 1.25rem;
  border-radius: var(--radius);
  border: none;
  font-size: 0.9375rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, opacity 0.15s, transform 0.1s;
  white-space: nowrap;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }

.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 1.5px solid var(--primary);
}
.btn-outline:hover:not(:disabled) { background: var(--primary-light); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}
.btn-ghost:hover:not(:disabled) { background: var(--border); color: var(--text); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 0.375rem 0.75rem; font-size: 0.875rem; }
.btn-full { width: 100%; }

/* ── Form elements ─────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 0.375rem; }

label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"],
input[type="number"],
input[type="search"],
select,
textarea {
  width: 100%;
  padding: 0.625rem 0.875rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 0.9375rem;
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79,70,229,.12);
}
textarea { resize: vertical; min-height: 90px; }

.input-wrap { position: relative; }
.input-wrap input { padding-right: 2.75rem; }
.input-wrap .toggle-pw {
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0.25rem;
  line-height: 1;
}
.input-wrap .toggle-pw:hover { color: var(--text); }

/* ── Alerts ────────────────────────────────────────────────── */
.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
}
.alert-error   { background: var(--danger-light); color: var(--danger); border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: var(--success); border: 1px solid #bbf7d0; }
.alert-info    { background: var(--primary-light); color: var(--primary-dark); border: 1px solid #c7d2fe; }

/* ── Status chips ──────────────────────────────────────────── */
.chip {
  display: inline-block;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 500;
}
.chip-pending          { background: #fef9c3; color: #854d0e; }
.chip-self-submitted   { background: #dbeafe; color: #1e40af; }
.chip-client-submitted { background: #dcfce7; color: #166534; }
.chip-inactive         { background: #f1f5f9; color: #64748b; }

/* ── Tables ────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th {
  text-align: left;
  padding: 0.625rem 1rem;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  border-bottom: 1.5px solid var(--border);
}
td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: #f8fafc; }

/* ── App shell ─────────────────────────────────────────────── */
.app-shell {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 100vh;
}

/* ── Topbar ────────────────────────────────────────────────── */
.topbar {
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--topbar-border);
  padding: 0 2rem;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
  box-shadow: var(--shadow-sm);
}
.topbar-left {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  flex-shrink: 0;
}
.topbar-brand {
  font-weight: 700;
  font-size: 1rem;
  color: var(--topbar-text);
  text-decoration: none;
  white-space: nowrap;
}
.topbar-nav {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 0.125rem;
}
.topbar-nav-link {
  padding: 0.375rem 0.75rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--topbar-text-muted);
  text-decoration: none;
  transition: color 0.15s, background 0.15s;
}
.topbar-nav-link:hover  { color: var(--topbar-text); background: rgba(0,0,0,.06); }
.topbar-nav-link.active { color: var(--primary); background: var(--primary-light); }
.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.875rem;
  color: var(--topbar-text-muted);
  flex-shrink: 0;
}
.btn-signout {
  background: transparent;
  color: var(--topbar-text-muted);
  border: 1.5px solid var(--topbar-text-muted);
  border-radius: 999px;
  padding: 0.3rem 0.875rem;
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s;
  white-space: nowrap;
}
.btn-signout:hover { opacity: 0.7; }

/* ── Page content ──────────────────────────────────────────── */
.page-content {
  padding: 2rem;
  max-width: 1100px;
  margin: 0 auto;
  width: 100%;
}
.page-header { margin-bottom: 1.5rem; }
.page-header h1 { margin-bottom: 0.25rem; }

/* ── Stat cards ────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card { background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow); padding: 1.25rem 1.5rem; }
.stat-value { font-size: 2rem; font-weight: 700; line-height: 1; color: var(--text); }
.stat-label { font-size: 0.8125rem; color: var(--text-muted); margin-top: 0.3rem; }

/* ── Modal ─────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 1rem;
}
.modal-box {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 60px rgba(0,0,0,.22);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  animation: modal-in 0.18s ease;
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(-12px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.modal-header {
  padding: 1.125rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-close {
  background: none;
  border: none;
  font-size: 1.25rem;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  border-radius: var(--radius);
}
.modal-close:hover { background: var(--bg); color: var(--text); }
.modal-body { padding: 1.5rem; display: flex; flex-direction: column; gap: 1.125rem; }
.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

/* ── Search bar ────────────────────────────────────────────── */
.search-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.search-wrap {
  position: relative;
  flex: 1;
  max-width: 480px;
}
.search-icon {
  position: absolute;
  left: 0.9375rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
  line-height: 0;
  transition: color 0.15s;
}
.search-wrap:focus-within .search-icon { color: var(--primary); }
.search-wrap input[type="search"] {
  padding: 0.75rem 1rem 0.75rem 2.75rem;
  border-radius: 2rem;
  box-shadow: 0 1px 4px rgba(0,0,0,.07);
}
.search-count {
  font-size: 0.8125rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ── Utility ───────────────────────────────────────────────── */
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.text-muted { color: var(--text-muted); font-size: 0.875rem; }
.hidden { display: none; }

/* ── Shake animation (login error) ────────────────────────── */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60%  { transform: translateX(-6px); }
  40%, 80%  { transform: translateX(6px); }
}
.shake { animation: shake 0.35s ease; }

/* ── Login page ────────────────────────────────────────────── */
.login-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.login-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 2rem;
  width: 100%;
  max-width: 380px;
}
.login-card h1 {
  font-size: 1.4rem;
  margin-bottom: 1.5rem;
  color: var(--text);
}
.error {
  color: var(--danger);
  font-size: 0.875rem;
}
