:root {
  --primary-start: #667eea;
  --primary-end: #764ba2;
  --bg-dark: #1a1a2e;
  --bg-card: #16213e;
  --bg-input: #0f3460;
  --text-light: #eaeaea;
  --text-muted: #a0a0a0;
  --success: #28a745;
  --warning: #ffc107;
  --danger: #dc3545;
  --info: #17a2b8;
  --topbar-h: 56px;
  --bottomnav-h: 60px;
}

* { -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-dark);
  color: var(--text-light);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

/* Top bar */
.app-topbar {
  height: var(--topbar-h);
  background: var(--bg-card);
  border-bottom: 1px solid rgba(255,255,255,0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  padding-top: env(safe-area-inset-top, 0);
  height: calc(var(--topbar-h) + env(safe-area-inset-top, 0));
  flex-shrink: 0;
}

.topbar-left, .topbar-right { display: flex; align-items: center; gap: 0.75rem; }

.app-title { font-weight: 700; font-size: 1.1rem; letter-spacing: 0.5px; }

.status-dot {
  width: 10px; height: 10px; border-radius: 50%;
  display: inline-block;
  transition: background-color 0.2s, box-shadow 0.2s;
}
.status-dot.online { background: var(--success); box-shadow: 0 0 6px var(--success); }
.status-dot.offline { background: var(--danger); box-shadow: 0 0 6px var(--danger); }
.status-dot.syncing { background: var(--warning); box-shadow: 0 0 6px var(--warning); animation: pulse 1s infinite; }

@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }

.btn-icon {
  background: transparent;
  border: none;
  color: var(--text-light);
  font-size: 1.25rem;
  padding: 0.5rem;
  border-radius: 8px;
  cursor: pointer;
}
.btn-icon:hover, .btn-icon:active { background: rgba(255,255,255,0.06); }
.btn-icon.spinning i { display: inline-block; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Route view */
.route-view {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 1rem;
  padding-bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom, 0) + 1rem);
  -webkit-overflow-scrolling: touch;
}

.boot-splash {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 50vh;
  color: var(--text-muted);
}

/* Cards matching mobile-dev design */
.pits-card {
  background: var(--bg-card);
  border-radius: 16px;
  padding: 1.25rem;
  margin-bottom: 1rem;
  border: 1px solid rgba(255,255,255,0.08);
}

.pits-hero {
  background: linear-gradient(135deg, var(--primary-start) 0%, var(--primary-end) 100%);
  border-radius: 16px;
  padding: 1.5rem;
  margin-bottom: 1rem;
  color: #fff;
}

/* Bottom nav */
.app-bottomnav {
  height: var(--bottomnav-h);
  height: calc(var(--bottomnav-h) + env(safe-area-inset-bottom, 0));
  padding-bottom: env(safe-area-inset-bottom, 0);
  background: var(--bg-card);
  border-top: 1px solid rgba(255,255,255,0.08);
  display: flex;
  justify-content: space-around;
  align-items: stretch;
  flex-shrink: 0;
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.7rem;
  transition: color 0.15s;
}
.nav-item i { font-size: 1.35rem; }
.nav-item.active, .nav-item:active { color: var(--primary-start); }

/* Forms */
.pits-input {
  background: var(--bg-input);
  border: 1px solid rgba(255,255,255,0.12);
  color: var(--text-light);
  border-radius: 10px;
  padding: 0.75rem 1rem;
  width: 100%;
  font-size: 1rem;
}
.pits-input:focus { outline: none; border-color: var(--primary-start); }

.pits-btn {
  background: linear-gradient(135deg, var(--primary-start) 0%, var(--primary-end) 100%);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 0.75rem 1.25rem;
  font-weight: 600;
  width: 100%;
  font-size: 1rem;
  cursor: pointer;
}
.pits-btn:disabled { opacity: 0.6; cursor: not-allowed; }

.pits-btn-secondary {
  background: transparent;
  color: var(--text-light);
  border: 1px solid rgba(255,255,255,0.18);
}

.text-muted { color: var(--text-muted) !important; }

/* Toasts */
.pits-toast {
  position: fixed;
  bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom, 0) + 1rem);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-card);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 10px;
  padding: 0.75rem 1.25rem;
  z-index: 1000;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  animation: toastIn 0.2s ease-out;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 20px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ========== Views added in v2 ========== */

/* Dashboard widgets */
.dash-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.dash-widget {
  background: var(--bg-card);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 14px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-height: 84px;
}
.dash-widget .dw-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.dash-widget .dw-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-light);
}
.dash-widget .dw-sub {
  font-size: 0.7rem;
  color: var(--text-muted);
}
.dash-widget.success .dw-value { color: var(--success); }
.dash-widget.warning .dw-value { color: var(--warning); }
.dash-widget.danger .dw-value { color: var(--danger); }
.dash-widget.info .dw-value { color: var(--info); }

.section-title {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 1rem 0 0.5rem;
}

/* Tab bar for filtering lists */
.tab-bar {
  display: flex;
  gap: 0.25rem;
  background: var(--bg-card);
  padding: 0.25rem;
  border-radius: 10px;
  margin-bottom: 1rem;
}
.tab {
  flex: 1;
  padding: 0.5rem;
  text-align: center;
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 0.85rem;
  cursor: pointer;
  border: none;
  background: transparent;
  transition: all 0.15s;
}
.tab.active {
  background: var(--bg-input);
  color: var(--text-light);
  font-weight: 600;
}

/* Generic list row */
.list-row {
  background: var(--bg-card);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  padding: 0.875rem 1rem;
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  cursor: pointer;
}
.list-row:active { background: rgba(255,255,255,0.03); }
.list-row .lr-body { flex: 1; min-width: 0; }
.list-row .lr-title {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.list-row .lr-sub {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-top: 2px;
}
.list-row .lr-meta {
  text-align: right;
  font-size: 0.75rem;
  color: var(--text-muted);
  flex-shrink: 0;
}
.list-row .lr-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  background: rgba(255,255,255,0.08);
}
.lr-badge.pending { background: rgba(255,193,7,0.15); color: var(--warning); }
.lr-badge.approved, .lr-badge.paid { background: rgba(40,167,69,0.15); color: var(--success); }
.lr-badge.rejected, .lr-badge.failed { background: rgba(220,53,69,0.15); color: var(--danger); }

/* Chat list */
.chat-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.chat-item {
  background: var(--bg-card);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  padding: 0.75rem;
  display: flex;
  gap: 0.75rem;
  align-items: center;
  cursor: pointer;
}
.chat-item:active { background: rgba(255,255,255,0.03); }
.chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary-start), var(--primary-end));
  color: #fff;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.chat-meta {
  flex: 1;
  min-width: 0;
}
.chat-name {
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
}
.chat-time {
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 400;
  flex-shrink: 0;
}
.chat-preview {
  color: var(--text-muted);
  font-size: 0.8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}
.chat-item .unread-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary-start);
  flex-shrink: 0;
}

/* Chat detail screen */
.chat-detail {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--topbar-h) - var(--bottomnav-h) - 2rem);
  margin: -1rem;
  margin-bottom: calc(-1 * var(--bottomnav-h) - env(safe-area-inset-bottom, 0) - 1rem);
}
.chat-header {
  background: var(--bg-card);
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
}
.chat-header-body { flex: 1; min-width: 0; }
.chat-header .chat-name { display: block; }
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.chat-bubble {
  max-width: 75%;
  padding: 0.625rem 0.875rem;
  border-radius: 14px;
  word-wrap: break-word;
  font-size: 0.9rem;
}
.chat-bubble.theirs {
  background: var(--bg-card);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}
.chat-bubble.mine {
  background: linear-gradient(135deg, var(--primary-start), var(--primary-end));
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}
.chat-bubble.pending { opacity: 0.6; }
.chat-bubble.failed { border: 1px solid var(--danger); }
.chat-text { white-space: pre-wrap; }
.chat-meta-line {
  font-size: 0.65rem;
  opacity: 0.7;
  margin-top: 4px;
  text-align: right;
}
.chat-attach {
  display: block;
  margin-top: 6px;
  max-width: 200px;
  border-radius: 8px;
  overflow: hidden;
}
.chat-attach img { width: 100%; display: block; }
.chat-composer {
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem;
  background: var(--bg-card);
  border-top: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
  padding-bottom: calc(0.5rem + env(safe-area-inset-bottom, 0));
}
.chat-composer .pits-input {
  border-radius: 20px;
  padding: 0.5rem 0.875rem;
}
.chat-composer .btn-send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary-start), var(--primary-end));
  color: #fff;
  border: none;
  flex-shrink: 0;
  font-size: 1rem;
  cursor: pointer;
}

/* Form groups */
.form-group { margin-bottom: 0.875rem; }
.form-label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.375rem;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

/* Alerts */
.pits-alert {
  background: var(--bg-card);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 10px;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.85rem;
}
.pits-alert.success { border-color: var(--success); color: var(--success); }
.pits-alert.danger { border-color: var(--danger); color: var(--danger); }
.pits-alert.warning { border-color: var(--warning); color: var(--warning); }
.pits-alert.info { border-color: var(--info); color: var(--info); }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-muted);
}
.empty-state i {
  font-size: 3rem;
  margin-bottom: 0.75rem;
  opacity: 0.5;
}

/* Role badge in topbar / menu */
.role-badge {
  font-size: 0.65rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(102,126,234,0.2);
  color: var(--primary-start);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

/* Menu/more page rows */
.menu-row {
  background: var(--bg-card);
  padding: 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  cursor: pointer;
}
.menu-row:first-child { border-radius: 12px 12px 0 0; }
.menu-row:last-child { border-radius: 0 0 12px 12px; border-bottom: none; }
.menu-row i { font-size: 1.25rem; color: var(--text-muted); }
.menu-row .mr-title { flex: 1; }
.menu-row .mr-sub { font-size: 0.75rem; color: var(--text-muted); margin-top: 2px; }
