:root {
  --primary: #0a2540;
  --primary-light: #1e4d8c;
  --accent: #2563eb;
  --text: #1a1a1a;
  --text-muted: #5a5a5a;
  --bg: #f8f9fb;
  --surface: #ffffff;
  --border: #e2e8f0;
  --shadow: 0 4px 12px rgba(10, 37, 64, 0.08);
  --radius: 12px;
  --header-height: 72px;
}

[data-theme="dark"] {
  --primary: #60a5fa;
  --primary-light: #93c5fd;
  --accent: #3b82f6;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --bg: #0f172a;
  --surface: #1e293b;
  --border: #334155;
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

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

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  padding-bottom: env(safe-area-inset-bottom);
}

/* Larger touch targets for iPhone / iPad */
.btn, .hamburger, .theme-toggle, .nav-link {
  min-height: 44px;
  touch-action: manipulation;
}

.btn {
  padding: 0.85rem 1.5rem;
}

input, select, textarea {
  font-size: 16px; /* prevents iOS zoom on focus */
  min-height: 44px;
}

@media (min-width: 768px) {
  .main { max-width: 900px; }
  .hero h1, .page-title { font-size: 1.6rem; }
  .hero-actions { gap: 1.25rem; }
}

@media (min-width: 1024px) {
  .main { max-width: 1000px; }
}

/* Header */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 64px;
  gap: 0.75rem;
}

.header-text {
  display: flex;
  flex-direction: column;
  gap: 0;
  min-width: 0;
  flex: 1;
}

.site-name {
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
}

.page-title {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.sync-status {
  font-size: 0.7rem;
  color: var(--text-muted);
  display: none; /* hide on small screens to keep header clean */
}

@media (min-width: 480px) {
  .sync-status { display: inline; }
}

.theme-toggle {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.hamburger {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  padding: 0;
}

.hamburger span {
  display: block;
  width: 16px;
  height: 2px;
  background: var(--text);
  border-radius: 1px;
}

.header-text {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.site-name {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 500;
}

.page-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

/* Hamburger */
.hamburger {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  padding: 0;
}

.hamburger span {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--text);
  border-radius: 1px;
  transition: 0.2s;
}

/* Drawer */
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: min(320px, 85vw);
  height: 100vh;
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 30;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 20px rgba(0,0,0,0.1);
}

.drawer.open {
  transform: translateX(0);
}

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

.drawer-logo {
  height: 36px;
  width: auto;
}

.close-drawer {
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  color: var(--text);
  padding: 0.25rem;
}

.drawer-nav {
  list-style: none;
  padding: 0.5rem 0;
  flex: 1;
  overflow-y: auto;
}

.drawer-nav li a,
.nav-link {
  display: block;
  padding: 0.9rem 1.5rem;
  color: var(--text);
  text-decoration: none;
  font-size: 1rem;
  font-weight: 500;
  border-left: 3px solid transparent;
}

.nav-link.active,
.nav-link:hover {
  background: var(--bg);
  border-left-color: var(--primary);
}

.drawer-divider {
  height: 1px;
  background: var(--border);
  margin: 0.5rem 1.5rem;
}

.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 25;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}

.drawer-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

/* Main */
.main {
  flex: 1;
  padding: 1.5rem;
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
}

.page {
  display: none;
}

.page.active {
  display: block;
}

.hero {
  text-align: center;
  padding: 1.5rem 0 2rem;
}

.hero-logo {
  height: 72px;
  width: auto;
  margin-bottom: 0.75rem;
}

.tagline {
  font-size: 1.05rem;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
}

.hero-actions {
  display: flex;
  gap: 1rem;
  justify-content: center;
  flex-wrap: wrap;
}

/* Uniform Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  border: 2px solid var(--primary);
  background: transparent;
  color: var(--primary);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, transform 0.1s;
  min-width: 140px;
  text-decoration: none;
}

.btn:active,
.btn:focus-visible {
  background: var(--primary);
  color: white;
  transform: scale(0.98);
}

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

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

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.75rem;
  box-shadow: var(--shadow);
  max-width: 480px;
  margin: 1rem auto;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.form-grid .full,
.form-actions.full {
  grid-column: 1 / -1;
}

.form-grid label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-weight: 500;
  font-size: 0.95rem;
}

.form-grid input,
.form-grid select {
  padding: 0.65rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  background: var(--bg);
  color: var(--text);
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 0.5rem;
}

.list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.list-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.9rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.list-item .meta {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.profile-docs {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.doc-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  background: var(--bg);
}

.doc-card h3 {
  margin-bottom: 0.75rem;
  font-size: 1.05rem;
}

.doc-card label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-bottom: 0.6rem;
  font-size: 0.95rem;
}

/* HOS Grid */
.hos-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: end;
  margin-bottom: 1.25rem;
}

.duty-buttons {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.btn.duty {
  min-width: auto;
  padding: 0.6rem 1rem;
  font-size: 0.95rem;
}

.hos-grid-wrap {
  overflow-x: auto;
  margin: 1rem 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.hos-grid {
  display: grid;
  grid-template-columns: 100px repeat(24, 28px);
  min-width: 780px;
  font-size: 0.75rem;
}

.hos-grid .hour-label,
.hos-grid .status-label {
  padding: 0.35rem 0.4rem;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  text-align: center;
  background: var(--bg);
}

.hos-grid .status-label {
  text-align: left;
  font-weight: 600;
}

.hos-grid .cell {
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  height: 28px;
  position: relative;
}

.hos-grid .cell.active {
  background: var(--primary);
  opacity: 0.85;
}

.hos-totals {
  display: flex;
  gap: 1.5rem;
  font-size: 0.9rem;
  margin: 0.75rem 0;
  flex-wrap: wrap;
}

.hos-totals span {
  font-weight: 600;
}

.maint-item {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}

.maint-item input[type="text"] {
  flex: 1;
  min-width: 200px;
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.admin-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  text-align: center;
}

.admin-card h3 {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.admin-card p {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--primary);
}

.inspection-view {
  margin-top: 1.5rem;
  padding: 1rem;
  border: 2px solid var(--primary);
  border-radius: 8px;
  background: var(--bg);
}

.status-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  margin-left: 0.4rem;
}
.status-pending { background: #fef3c7; color: #92400e; }
.status-open { background: #dbeafe; color: #1e40af; }
.status-certified { background: #d1fae5; color: #065f46; }
.status-archived { background: #e5e7eb; color: #374151; }
[data-theme="dark"] .status-pending { background: #78350f; color: #fde68a; }
[data-theme="dark"] .status-open { background: #1e3a8a; color: #bfdbfe; }
[data-theme="dark"] .status-certified { background: #064e3b; color: #a7f3d0; }
[data-theme="dark"] .status-archived { background: #374151; color: #d1d5db; }

.changelog {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.changelog-entry {
  border-left: 3px solid var(--primary);
  padding-left: 1rem;
}

.changelog-version {
  font-weight: 700;
  color: var(--primary);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.changelog-date {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.login-form label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-weight: 500;
  font-size: 0.95rem;
}

.login-form input {
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  background: var(--bg);
  color: var(--text);
}

.login-form input:focus {
  outline: 2px solid var(--accent);
  border-color: transparent;
}

.hint {
  margin-top: 1rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: center;
}

/* Footer */
.footer {
  text-align: center;
  padding: 1.25rem;
  color: var(--text-muted);
  font-size: 0.9rem;
  border-top: 1px solid var(--border);
  margin-top: auto;
}

.build-number {
  margin-top: 0.35rem;
  font-size: 0.75rem;
  opacity: 0.6;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

@media (max-width: 600px) {
  .page-title {
    font-size: 1.3rem;
  }
  .header {
    padding: 0.6rem 1rem;
  }
}
