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

:root {
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'Courier New', monospace;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,0.15);
  --transition: 0.2s ease;
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--surface, #FFFBFE);
  color: var(--on-surface, #1C1B1F);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

body {
  display: flex;
  flex-direction: column;
}

#top-bar {
  flex-shrink: 0;
  z-index: 100;
}

.refresh-status {
  flex-shrink: 0;
  padding: 4px 16px;
  font-size: 12px;
  background: var(--secondary-container, #E8DEF8);
  color: var(--on-secondary-container, #1D192B);
  text-align: center;
  transition: max-height var(--transition), opacity var(--transition);
  max-height: 30px;
  overflow: hidden;
}
.refresh-status.hidden { max-height: 0; opacity: 0; padding: 0 16px; }

#app {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

#bottom-nav {
  flex-shrink: 0;
  z-index: 100;
}

/* Typography */
h1 { font-size: 24px; font-weight: 700; }
h2 { font-size: 20px; font-weight: 600; }
h3 { font-size: 16px; font-weight: 600; }
.text-sm { font-size: 13px; }
.text-xs { font-size: 11px; }
.text-lg { font-size: 18px; }
.text-xl { font-size: 24px; }
.text-2xl { font-size: 32px; }
.text-bold { font-weight: 700; }
.text-muted { opacity: 0.7; }
.text-center { text-align: center; }

/* Colors */
.text-green { color: #2E7D32; }
.text-red { color: #C62828; }
.text-primary { color: var(--primary); }
.bg-green { background: #2E7D32; color: white; }
.bg-red { background: #C62828; color: white; }

/* Layout helpers */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.gap-4 { gap: 4px; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.p-8 { padding: 8px; }
.p-12 { padding: 12px; }
.p-16 { padding: 16px; }
.px-16 { padding-left: 16px; padding-right: 16px; }
.py-8 { padding-top: 8px; padding-bottom: 8px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.w-full { width: 100%; }
.hidden { display: none !important; }
.overflow-x { overflow-x: auto; }

/* Loading */
.loading-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 16px;
}

.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--surface-variant, #E7E0EC);
  border-top-color: var(--primary, #2E7D32);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), opacity var(--transition);
  font-family: var(--font);
}
.btn:active { opacity: 0.8; }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-secondary { background: var(--secondary-container, #E8DEF8); color: var(--on-secondary-container, #1D192B); }
.btn-error { background: var(--error, #B3261E); color: var(--on-error, #fff); }
.btn-outline { background: transparent; border: 1px solid var(--outline); color: var(--on-surface); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-icon { padding: 8px; border-radius: 50%; background: none; border: none; cursor: pointer; color: var(--on-surface); }
.btn-icon:hover { background: var(--surface-variant, rgba(0,0,0,0.05)); }

/* Input */
.input, .select, .textarea {
  padding: 10px 12px;
  border: 1px solid var(--outline, #79747E);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: var(--font);
  background: var(--surface);
  color: var(--on-surface);
  width: 100%;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary);
}
.textarea { resize: vertical; min-height: 60px; }

label {
  font-size: 12px;
  font-weight: 500;
  color: var(--on-surface);
  opacity: 0.7;
  margin-bottom: 4px;
  display: block;
}

/* Cards */
.card {
  background: var(--surface-container, var(--surface));
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

/* Screen padding */
.screen { padding: 16px; }
.screen-title { font-size: 20px; font-weight: 600; margin-bottom: 16px; }

/* Tabs */
.tab-bar {
  display: flex;
  border-bottom: 2px solid var(--surface-variant, #E7E0EC);
  overflow-x: auto;
}
.tab {
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  background: none;
  color: var(--on-surface);
  opacity: 0.6;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  white-space: nowrap;
  font-family: var(--font);
}
.tab.active {
  opacity: 1;
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* Dialog overlay */
.dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
}
.dialog-overlay.hidden { display: none; }

.dialog {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
  padding: 24px;
  max-width: 400px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
}
.dialog-title { font-size: 18px; font-weight: 600; margin-bottom: 12px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--outline, #79747E); border-radius: 3px; }
