:root {
  --outer-bg: #0b0c0e;
  --bg: #121417;
  --surface: #1a1d22;
  --surface-2: #21252c;
  --border: #2c313a;
  --text: #f2f0ec;
  --muted: #9aa1ac;
  --accent: #d97736;
  --accent-hover: #c56729;
  --accent-soft: rgba(217, 119, 54, 0.14);
  --green: #2f9e66;
  --green-soft: rgba(47, 158, 102, 0.15);
  --red: #d94e4e;
  --red-soft: rgba(217, 78, 78, 0.15);
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--outer-bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.45;
  height: 100%;
}

.hidden { display: none !important; }

.phone-shell {
  width: 100%;
  max-width: 480px;
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--bg);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: relative;
}

@media (max-width: 480px) {
  .phone-shell {
    border-left: none;
    border-right: none;
  }
}

.toast {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 9px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  max-width: 440px;
  width: calc(100% - 32px);
  text-align: center;
  box-shadow: 0 8px 24px rgba(0,0,0,0.45);
}
.toast.error { border-color: var(--red); color: #ffd4d4; }
.toast.ok { border-color: var(--green); }

/* Auth */
.auth-view {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-card {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

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

.brand-logo {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  border: 1px solid var(--border);
  object-fit: cover;
}

.brand-title {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-sub {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
}

/* Form & Inputs */
.stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field span {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
}

input, textarea, select {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-family: var(--sans);
  font-size: 14px;
  outline: none;
}

textarea {
  font-family: var(--mono);
  font-size: 12.5px;
  resize: vertical;
}

input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
}

.btn {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

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

.btn-ghost {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}

.btn-danger {
  background: var(--red-soft);
  color: #f49b9b;
  border-color: rgba(217, 78, 78, 0.35);
}

.btn-sm { padding: 8px 11px; font-size: 12.5px; }
.btn-xs { padding: 5px 9px; font-size: 12px; }

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.icon-btn svg { width: 17px; height: 17px; }
.icon-btn:hover { color: var(--text); }

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px;
  gap: 3px;
}

.seg-btn {
  background: transparent;
  color: var(--muted);
  border: none;
  border-radius: 6px;
  padding: 7px 8px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}
.seg-btn.active {
  background: var(--surface-2);
  color: var(--text);
}

.hint {
  font-size: 12px;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
}

/* App Shell */
.app-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding-bottom: 66px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.topbar-logo {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  border: 1px solid var(--border);
}

.topbar-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar-title {
  font-size: 14.5px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-sub {
  font-size: 11px;
  color: var(--muted);
  font-family: var(--mono);
  text-transform: uppercase;
}

.content {
  flex: 1;
  padding: 14px;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Cards */
.quota-card, .card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
}

.card.active-project {
  border-color: var(--accent);
}

.quota-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
}

.quota-right { text-align: right; }

.quota-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.quota-value {
  font-size: 14px;
  font-weight: 700;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

.progress-track {
  height: 6px;
  background: var(--bg);
  border-radius: 99px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 99px;
  transition: width 0.2s ease;
}

.inline-create {
  display: flex;
  gap: 8px;
}
.inline-create input { flex: 1; }

.banner-warn {
  background: var(--accent-soft);
  border: 1px solid rgba(217, 119, 54, 0.35);
  color: #f3be99;
  font-size: 12px;
  padding: 9px 11px;
  border-radius: 8px;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.card-title {
  font-size: 14.5px;
  font-weight: 700;
}

.badge {
  font-family: var(--mono);
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 5px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
}

.badge.accent {
  background: var(--accent-soft);
  border-color: rgba(217, 119, 54, 0.4);
  color: var(--accent);
}

.badge.green {
  background: var(--green-soft);
  border-color: rgba(47, 158, 102, 0.4);
  color: #7ee2ad;
}

.badge.red {
  background: var(--red-soft);
  border-color: rgba(217, 78, 78, 0.4);
  color: #f49b9b;
}

.meta-line {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 6px;
  word-break: break-all;
}

.key-box {
  margin-top: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 7px 9px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.key-text {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.toggle-row {
  display: flex;
  gap: 12px;
  margin-top: 9px;
  padding-top: 9px;
  border-top: 1px solid var(--border);
}

.toggle-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
}

.toggle-label input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
}

/* Database Explorer */
.toolbar {
  display: flex;
  gap: 6px;
}
.toolbar input { flex: 1; padding: 8px 10px; font-size: 13px; }

.collection-bar {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.chip {
  white-space: nowrap;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 99px;
  padding: 5px 11px;
  font-size: 12px;
  font-family: var(--mono);
  cursor: pointer;
}
.chip.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--text);
}

.stream-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
}

.stream-left {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--muted);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}
.dot.live { background: var(--green); }

.stream-log {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-family: var(--mono);
  font-size: 11px;
  max-height: 130px;
  overflow-y: auto;
  color: #cbd2dc;
}

.json-pre {
  margin: 8px 0 0;
  padding: 9px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  font-family: var(--mono);
  font-size: 11.5px;
  overflow-x: auto;
  color: #e4e1db;
}

/* Storage */
.upload-box {
  border: 1px dashed var(--border);
  background: var(--surface);
  border-radius: 10px;
  padding: 18px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
}
.upload-box svg { width: 22px; height: 22px; color: var(--accent); }
.upload-box:hover { border-color: var(--accent); color: var(--text); }

.file-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.file-thumb {
  width: 44px;
  height: 44px;
  border-radius: 7px;
  object-fit: cover;
  border: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}

.file-icon-box {
  width: 44px;
  height: 44px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--accent);
  flex-shrink: 0;
}

.file-info { flex: 1; min-width: 0; }
.file-name {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Admin */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 10px;
}

.stat-k { font-size: 11px; color: var(--muted); }
.stat-v {
  font-size: 16px;
  font-weight: 700;
  font-family: var(--mono);
  margin-top: 2px;
}

.inline-num {
  width: 70px;
  padding: 5px 7px;
  font-size: 12px;
  font-family: var(--mono);
}

.empty-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

/* Bottom Navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 30;
}

.nav-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-size: 10.5px;
  font-weight: 600;
  cursor: pointer;
}
.nav-btn svg { width: 19px; height: 19px; }
.nav-btn.active { color: var(--accent); }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 60;
}

.modal-sheet {
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-radius: 14px 14px 0 0;
  padding: 16px;
  max-height: 88dvh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.modal-header h2 {
  margin: 0;
  font-size: 16px;
}

.query-row {
  display: flex;
  gap: 6px;
  align-items: center;
}
.query-row input, .query-row select {
  padding: 8px 10px;
  font-size: 12.5px;
  font-family: var(--mono);
}

.log-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-family: var(--mono);
  font-size: 11.5px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.log-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
