:root {
  --primary: #00687a;
  --primary-hover: #005160;
  --primary-light: #e0f2fe;
  --primary-container: #b5ebff;
  --on-primary: #ffffff;
  --on-primary-container: #001f27;
  --surface: #ffffff;
  --surface-variant: #e2e8f0;
  --on-surface-variant: #475569;
  --background: #f8fafc;
  --emerald: #059669;
  --emerald-light: #d1fae5;
  --emerald-dark: #065f46;
  --amber: #d97706;
  --amber-light: #fef3c7;
  --amber-dark: #92400e;
  --rose: #e11d48;
  --rose-light: #ffe4e6;
  --rose-dark: #9f1239;
  --purple: #7c3aed;
  --purple-light: #ede9fe;
  --slate-50: #f8fafc;
  --slate-100: #f1f5f9;
  --slate-200: #e2e8f0;
  --slate-300: #cbd5e1;
  --slate-400: #94a3b8;
  --slate-600: #475569;
  --slate-700: #334155;
  --slate-800: #1e293b;
  --slate-900: #0f172a;
  --radius: 14px;
  --radius-sm: 8px;
  --radius-full: 9999px;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 14px -2px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 12px 24px -4px rgba(0, 0, 0, 0.12);
  --bottom-nav-height: 64px;
  --topbar-height: 58px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-color: var(--background);
  color: var(--slate-800);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

.mono {
  font-family: 'JetBrains Mono', monospace;
}

/* =========================================
   APP ROOT & RESPONSIVE LAYOUT
   ========================================= */
.app-root {
  display: flex;
  width: 100%;
  min-height: 100vh;
}

/* Sidebar for Desktop */
aside.sidebar {
  display: none;
  width: 280px;
  background: var(--slate-900);
  color: #fff;
  flex-direction: column;
  flex-shrink: 0;
  border-right: 1px solid var(--slate-800);
  z-index: 50;
  height: 100vh;
  position: sticky;
  top: 0;
}

@media (min-width: 1024px) {
  aside.sidebar {
    display: flex;
  }
}

.sidebar-header {
  padding: 18px 20px;
  background: var(--primary);
  color: #fff;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon-box {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
}

.brand-text h2 {
  font-size: 1.05rem;
  font-weight: 900;
  letter-spacing: 0.5px;
  line-height: 1.2;
}

.brand-text p {
  font-size: 0.72rem;
  opacity: 0.85;
}

.user-status-card {
  margin-top: 12px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 10px;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  transition: background 0.15s ease;
}

.user-status-card:hover {
  background: rgba(255, 255, 255, 0.22);
}

.user-status-info {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
}

.user-status-name {
  font-size: 0.78rem;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-status-role {
  font-size: 0.68rem;
  opacity: 0.85;
}

.stats-row {
  margin-top: 8px;
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  opacity: 0.9;
}

/* Nav Menu */
.sidebar-nav {
  flex: 1;
  padding: 12px 10px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-section-title {
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.8px;
  color: var(--primary-light);
  padding: 12px 14px 4px;
  text-transform: uppercase;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 14px;
  color: var(--slate-400);
  border-radius: 10px;
  cursor: pointer;
  font-size: 0.84rem;
  font-weight: 600;
  transition: all 0.15s ease;
  min-height: 44px;
  text-decoration: none;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
}

.nav-item.active {
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(0, 104, 122, 0.35);
}

.nav-badge {
  margin-left: auto;
  font-size: 0.7rem;
  padding: 2px 7px;
  border-radius: 999px;
  font-weight: 700;
}

.nav-badge.badge-count {
  background: var(--primary-light);
  color: var(--primary);
}

.nav-badge.badge-alert {
  background: var(--rose-light);
  color: var(--rose-dark);
}

.nav-lock {
  margin-left: auto;
  font-size: 0.75rem;
  color: var(--rose);
}

/* Mobile Drawer Overlay */
.mobile-drawer-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  z-index: 100;
}

.mobile-drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: 320px;
  max-width: 85vw;
  background: var(--slate-900);
  z-index: 101;
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 4px 0 24px rgba(0,0,0,0.3);
}

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

/* Viewport */
main.viewport {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  position: relative;
  background: var(--background);
  width: 100%;
}

/* Top App Bar */
header.appbar {
  height: var(--topbar-height);
  background: #ffffff;
  border-bottom: 1px solid var(--slate-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  position: sticky;
  top: 0;
  z-index: 40;
}

.appbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--slate-700);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.2rem;
  transition: background 0.15s ease;
}

.btn-icon:hover, .btn-icon:active {
  background: var(--slate-100);
}

.appbar-title-box h1 {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--slate-900);
  line-height: 1.2;
}

.appbar-subtitle {
  font-size: 0.7rem;
  color: var(--primary);
  font-weight: 600;
}

.appbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Cloudfire Sync Pill */
.cloudfire-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(5, 150, 105, 0.12);
  color: var(--emerald-dark);
  border: 1px solid rgba(5, 150, 105, 0.25);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all 0.15s ease;
}

.cloudfire-pill:hover {
  background: rgba(5, 150, 105, 0.18);
}

.pulse-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--emerald);
  box-shadow: 0 0 0 2px rgba(5, 150, 105, 0.2);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(5, 150, 105, 0.5); }
  70% { transform: scale(1.1); box-shadow: 0 0 0 6px rgba(5, 150, 105, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(5, 150, 105, 0); }
}

/* Auth Pill */
.auth-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--primary-light);
  color: var(--primary);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  border: 1px solid rgba(0, 104, 122, 0.2);
  cursor: pointer;
}

/* Notifications Button */
.notif-btn {
  position: relative;
}

.notif-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  background: var(--rose);
  color: #fff;
  font-size: 0.64rem;
  font-weight: 800;
  min-width: 17px;
  height: 17px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #fff;
}

/* Bottom Nav Dock */
nav.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--bottom-nav-height);
  background: #ffffff;
  border-top: 1px solid var(--slate-200);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 45;
  box-shadow: 0 -2px 10px rgba(0,0,0,0.04);
}

@media (min-width: 1024px) {
  nav.bottom-nav {
    display: none;
  }
}

.bottom-tab {
  flex: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: none;
  background: transparent;
  color: var(--slate-600);
  font-size: 0.68rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.bottom-tab:active {
  background: var(--slate-100);
}

.bottom-tab.active {
  color: var(--primary);
  font-weight: 800;
}

.bottom-tab-icon {
  font-size: 1.25rem;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Content Area */
.content-area {
  flex: 1;
  padding: 16px;
  padding-bottom: calc(var(--bottom-nav-height) + 24px);
  max-width: 1100px;
  margin: 0 auto;
  width: 100%;
}

@media (min-width: 1024px) {
  .content-area {
    padding: 24px 32px 48px;
  }
}

/* Subtabs bar (Matches Android horizontal ScrollableTabRow) */
.subtabs-bar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
  margin-bottom: 14px;
  -webkit-overflow-scrolling: touch;
}

.subtab-pill {
  padding: 7px 16px;
  border-radius: var(--radius-full);
  font-size: 0.78rem;
  font-weight: 700;
  border: 1px solid var(--slate-300);
  background: #ffffff;
  color: var(--slate-700);
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: all 0.15s ease;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.subtab-pill:hover {
  border-color: var(--slate-400);
}

.subtab-pill.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(0, 104, 122, 0.25);
}

/* Search Bar (Matches SearchBarWidget) */
.search-widget {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fff;
  border: 1px solid var(--slate-300);
  border-radius: 12px;
  padding: 8px 14px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}

.search-widget input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 0.88rem;
  color: var(--slate-800);
  background: transparent;
}

.search-widget span {
  color: var(--slate-400);
  font-size: 1.1rem;
}

/* KPI Card Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

@media (min-width: 640px) {
  .kpi-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

.kpi-card {
  background: #fff;
  border: 1px solid var(--slate-200);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
}

.kpi-title {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--slate-600);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.kpi-value {
  font-size: 1.45rem;
  font-weight: 800;
  color: var(--slate-900);
  margin: 4px 0 2px;
}

.kpi-sub {
  font-size: 0.72rem;
  color: var(--slate-600);
}

/* Cards & List Items */
.card {
  background: #ffffff;
  border: 1px solid var(--slate-200);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.card-title {
  font-size: 0.96rem;
  font-weight: 800;
  color: var(--slate-900);
}

/* Status Chips */
.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.7rem;
  font-weight: 800;
  padding: 3px 9px;
  border-radius: 6px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.chip-green { background: var(--emerald-light); color: var(--emerald-dark); }
.chip-amber { background: var(--amber-light); color: var(--amber-dark); }
.chip-blue { background: var(--primary-light); color: var(--primary); }
.chip-rose { background: var(--rose-light); color: var(--rose-dark); }
.chip-purple { background: var(--purple-light); color: var(--purple); }
.chip-slate { background: var(--slate-200); color: var(--slate-700); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  font-size: 0.84rem;
  font-weight: 700;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  min-height: 42px;
  text-decoration: none;
}

.btn:active {
  transform: scale(0.98);
}

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

.btn-outline {
  background: #fff;
  color: var(--slate-700);
  border-color: var(--slate-300);
}
.btn-outline:hover {
  background: var(--slate-50);
  border-color: var(--slate-400);
}

.btn-success { background: var(--emerald); color: #fff; }
.btn-danger { background: var(--rose); color: #fff; }

.btn-sm {
  padding: 5px 10px;
  font-size: 0.74rem;
  min-height: 34px;
  border-radius: 8px;
}

/* Floating Action Button (FAB) */
.fab {
  position: fixed;
  right: 20px;
  bottom: calc(var(--bottom-nav-height) + 16px);
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-full);
  padding: 12px 20px;
  box-shadow: 0 6px 20px rgba(0, 104, 122, 0.4);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  z-index: 45;
  transition: transform 0.15s ease;
}

.fab:active {
  transform: scale(0.96);
}

@media (min-width: 1024px) {
  .fab {
    bottom: 28px;
    right: 28px;
  }
}

/* Modals & Bottom Sheets */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(4px);
  z-index: 105;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-window {
  background: #fff;
  border-radius: 18px;
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  padding: 22px;
  position: relative;
}

@media (max-width: 640px) {
  .modal-overlay {
    align-items: flex-end;
    padding: 0;
  }
  .modal-window {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    max-height: 85vh;
    padding: 20px 16px 28px;
  }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--slate-200);
  padding-bottom: 12px;
}

.modal-header h3 {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--slate-900);
}

.form-group {
  margin-bottom: 12px;
}

.form-label {
  display: block;
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--slate-700);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--slate-300);
  border-radius: 8px;
  font-size: 0.88rem;
  background: #fff;
  min-height: 42px;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0, 104, 122, 0.15);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

@media (min-width: 600px) {
  .form-row {
    grid-template-columns: 1fr 1fr;
  }
}

/* Auth Gate Container */
.auth-gate-card {
  background: #fff;
  border: 1px solid var(--slate-200);
  border-radius: var(--radius);
  padding: 32px 20px;
  text-align: center;
  max-width: 540px;
  margin: 30px auto;
  box-shadow: var(--shadow-md);
}

.auth-gate-icon {
  width: 64px;
  height: 64px;
  background: var(--rose-light);
  color: var(--rose-dark);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  margin: 0 auto 16px;
}

/* Digital Signature Canvas */
.signature-box {
  border: 2px dashed var(--slate-300);
  border-radius: 12px;
  background: #fff;
  position: relative;
  margin: 12px 0;
  touch-action: none;
}

canvas#signatureCanvas {
  width: 100%;
  height: 180px;
  display: block;
}

.signature-line {
  position: absolute;
  bottom: 30px;
  left: 20px;
  right: 20px;
  border-bottom: 1px solid var(--slate-300);
  text-align: center;
  font-size: 0.7rem;
  color: var(--slate-400);
  pointer-events: none;
}
