/* ==============================================
   Zen-iOS Hybrid Design System
   Physical tactility, frosted glass, cool gray palette
   ============================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&display=swap');

:root {
  /* Base — iOS system grays, never pure white */
  --bg-root: #F2F2F7;
  --bg-elevated: #F9F9FB;
  --bg-card: rgba(255, 255, 255, 0.52);
  --bg-card-hover: rgba(255, 255, 255, 0.68);
  --bg-input: rgba(235, 235, 240, 0.55);
  --bg-glass: rgba(255, 255, 255, 0.45);

  /* Text — high contrast cool gray scale */
  --text-primary: #1C1C1E;
  --text-secondary: #3A3A3C;
  --text-tertiary: #8E8E93;
  --text-quaternary: #AEAEB2;

  /* Accent — iOS blue */
  --accent: #007AFF;
  --accent-hover: #0062CC;
  --accent-glass: rgba(0, 122, 255, 0.10);

  /* Semantic */
  --danger: #FF3B30;
  --danger-bg: rgba(255, 59, 48, 0.08);
  --success: #34C759;
  --success-bg: rgba(52, 199, 89, 0.10);
  --warning: #FF9500;
  --warning-bg: rgba(255, 149, 0, 0.10);

  /* Borders — dual stroke system */
  --stroke-inner: rgba(255, 255, 255, 0.65);
  --stroke-outer: rgba(0, 0, 0, 0.06);
  --stroke-subtle: rgba(0, 0, 0, 0.04);
  --stroke-input: rgba(0, 0, 0, 0.08);

  /* Shadows — physical depth */
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-sm: 0 4px 12px -4px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 12px 32px -8px rgba(0, 0, 0, 0.07);
  --shadow-lg: 0 24px 48px -12px rgba(0, 0, 0, 0.09);
  --shadow-xl: 0 40px 80px -20px rgba(0, 0, 0, 0.10);
  --shadow-inset: inset 0 1px 3px rgba(0, 0, 0, 0.07);
  --shadow-inset-deep: inset 0 2px 6px rgba(0, 0, 0, 0.10);

  /* Radius — iOS continuous curvature */
  --radius-xs: 8px;
  --radius-sm: 12px;
  --radius-md: 20px;
  --radius-lg: 28px;
  --radius-xl: 40px;
  --radius-2xl: 50px;
  --radius-full: 9999px;

  /* Typography */
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', sans-serif;
  --font-mono: 'SF Mono', 'Cascadia Code', 'Fira Code', 'Menlo', monospace;

  /* Motion */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --duration-fast: 150ms;
  --duration-normal: 250ms;
  --duration-slow: 400ms;
}

/* ==============================================
   Reset & Base
   ============================================== */

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg-root);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  letter-spacing: -0.01em;
}

button, input, select, textarea {
  font: inherit;
  letter-spacing: inherit;
}

a {
  color: var(--accent);
  text-decoration: none;
  cursor: pointer;
  transition: opacity var(--duration-fast) var(--ease-out);
}
a:hover { opacity: 0.75; }

code, pre {
  font-family: var(--font-mono);
  font-size: 0.88em;
}

/* ==============================================
   Typography
   ============================================== */

h1, h2, h3 {
  font-weight: 800;
  letter-spacing: -0.03em;
  margin: 0;
}
h1 { font-size: 1.75rem; }
h2 { font-size: 1.15rem; letter-spacing: -0.02em; }

/* Industrial label — uppercase, tracked, tiny */
.eyebrow {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-tertiary);
}

/* ==============================================
   Layout — Breathing Whitespace
   ============================================== */

.shell {
  width: min(1320px, calc(100vw - 3rem));
  margin: 0 auto;
  padding: 2.5rem 0;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
  flex-wrap: wrap;
  gap: 1rem;
}
.header h1 { font-size: 2rem; font-weight: 900; letter-spacing: -0.04em; }
.header .user-info {
  display: flex;
  align-items: center;
  gap: 1rem;
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 0.9rem;
}

/* ==============================================
   Frosted Glass Panel — The Core Card
   ============================================== */

.panel {
  position: relative;
  background: var(--bg-card);
  backdrop-filter: blur(50px) saturate(1.4);
  -webkit-backdrop-filter: blur(50px) saturate(1.4);
  border: 1px solid var(--stroke-inner);
  outline: 1px solid var(--stroke-outer);
  outline-offset: -2px;
  border-radius: var(--radius-xl);
  box-shadow:
    var(--shadow-sm),
    0 0 0 1px rgba(0, 0, 0, 0.02);
  padding: 1.75rem 2rem;
  margin-bottom: 1.25rem;
  transition:
    box-shadow var(--duration-normal) var(--ease-out),
    background var(--duration-normal) var(--ease-out);
}

.panel:hover {
  background: var(--bg-card-hover);
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  gap: 1rem;
}
.panel-title h2 {
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

/* Subtle panel variant — less prominent */
.panel-soft {
  background: rgba(255, 255, 255, 0.35);
  backdrop-filter: blur(30px);
  -webkit-backdrop-filter: blur(30px);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
}
.panel-soft:hover {
  background: rgba(255, 255, 255, 0.50);
}

/* ==============================================
   Grid Layouts
   ============================================== */

.grid2 { display: grid; gap: 1.25rem; grid-template-columns: 1fr 1fr; }
.grid3 { display: grid; gap: 1.25rem; grid-template-columns: repeat(3, 1fr); }
.grid4 { display: grid; gap: 1.25rem; grid-template-columns: repeat(4, 1fr); }

@media (max-width: 1024px) {
  .grid4 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 860px) {
  .grid2, .grid3, .grid4, .form-row { grid-template-columns: 1fr; }
}

/* ==============================================
   Buttons — Physical Tactile Feedback
   ============================================== */

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--radius-full);
  cursor: pointer;
  font-weight: 700;
  font-size: 0.9rem;
  padding: 0.7rem 1.5rem;
  white-space: nowrap;
  letter-spacing: -0.01em;
  transition:
    transform var(--duration-fast) var(--ease-spring),
    box-shadow var(--duration-fast) var(--ease-out),
    background var(--duration-fast) var(--ease-out),
    opacity var(--duration-fast) var(--ease-out);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* Primary — Deep Space Black */
button:not(.secondary):not(.danger):not(.small) {
  background: #1C1C1E;
  color: #FFFFFF;
  box-shadow:
    0 2px 8px rgba(0, 0, 0, 0.12),
    0 8px 20px -8px rgba(0, 0, 0, 0.15);
}
button:not(.secondary):not(.danger):not(.small):hover {
  background: #2C2C2E;
  box-shadow:
    0 4px 14px rgba(0, 0, 0, 0.16),
    0 12px 28px -8px rgba(0, 0, 0, 0.18);
  transform: translateY(-1px);
}
button:not(.secondary):not(.danger):not(.small):active {
  transform: scale(0.97);
  box-shadow:
    0 1px 4px rgba(0, 0, 0, 0.10);
  transition-duration: 50ms;
}

/* Secondary — Frosted White */
button.secondary {
  background: rgba(255, 255, 255, 0.75);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.8);
  outline: 1px solid rgba(0, 0, 0, 0.06);
  outline-offset: -2px;
  color: var(--text-primary);
  box-shadow: var(--shadow-xs);
}
button.secondary:hover {
  background: rgba(255, 255, 255, 0.95);
  box-shadow: var(--shadow-sm);
}
button.secondary:active {
  transform: scale(0.97);
  background: rgba(240, 240, 245, 0.95);
  transition-duration: 50ms;
}

/* Danger */
button.danger {
  background: var(--danger-bg);
  color: var(--danger);
  font-weight: 600;
}
button.danger:hover {
  background: rgba(255, 59, 48, 0.15);
  color: #E0352B;
}
button.danger:active {
  transform: scale(0.97);
  transition-duration: 50ms;
}

/* Small */
button.small {
  padding: 0.45rem 1rem;
  font-size: 0.82rem;
  border-radius: var(--radius-full);
}
button.small:not(.secondary):not(.danger) {
  background: #1C1C1E;
  color: #FFFFFF;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.10);
}
button.small.secondary {
  background: rgba(255, 255, 255, 0.75);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  color: var(--text-primary);
}
button.small.danger {
  background: var(--danger-bg);
  color: var(--danger);
}
button.small:active {
  transform: scale(0.96);
  transition-duration: 50ms;
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

/* ==============================================
   Form Controls — Engraved / Inset
   ============================================== */

label {
  color: var(--text-secondary);
  display: grid;
  gap: 0.45rem;
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

input, select, textarea {
  background: var(--bg-input);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--stroke-input);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  padding: 0.8rem 1rem;
  width: 100%;
  font-size: 0.92rem;
  box-shadow: var(--shadow-inset);
  transition:
    border-color var(--duration-fast) var(--ease-out),
    box-shadow var(--duration-fast) var(--ease-out),
    background var(--duration-fast) var(--ease-out);
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow:
    var(--shadow-inset),
    0 0 0 3px var(--accent-glass);
  background: rgba(255, 255, 255, 0.7);
}

input::placeholder, textarea::placeholder {
  color: var(--text-quaternary);
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238E8E93' stroke-width='2.5'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 1rem center;
  padding-right: 2.5rem;
  cursor: pointer;
}

/* Checkbox */
.checkbox {
  display: flex !important;
  align-items: center;
  gap: 0.7rem;
  cursor: pointer;
}
.checkbox input[type="checkbox"] {
  width: 1.2rem;
  height: 1.2rem;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ==============================================
   Form Layout
   ============================================== */

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

.form-actions {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

/* ==============================================
   Tables — Clean & Airy
   ============================================== */

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
thead th {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.10em;
  color: var(--text-tertiary);
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--stroke-subtle);
  text-align: left;
}
tbody td {
  padding: 0.8rem 1rem;
  border-bottom: 1px solid rgba(0, 0, 0, 0.03);
  color: var(--text-primary);
}
tbody tr {
  transition: background var(--duration-fast) var(--ease-out);
}
tbody tr:hover td {
  background: rgba(0, 0, 0, 0.02);
}

/* ==============================================
   Stats Cards
   ============================================== */

.stat-card {
  background: var(--bg-card);
  backdrop-filter: blur(40px);
  -webkit-backdrop-filter: blur(40px);
  border: 1px solid var(--stroke-inner);
  outline: 1px solid var(--stroke-outer);
  outline-offset: -2px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 1.5rem;
  text-align: center;
  transition:
    transform var(--duration-normal) var(--ease-out),
    box-shadow var(--duration-normal) var(--ease-out);
}
.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}
.stat-card .value {
  font-size: 2.5rem;
  font-weight: 900;
  letter-spacing: -0.04em;
  color: var(--text-primary);
  line-height: 1.1;
}
.stat-card .label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.10em;
  color: var(--text-tertiary);
  margin-top: 0.35rem;
}

/* ==============================================
   Quota Bars
   ============================================== */

.quota-bar { margin-bottom: 1rem; }
.quota-bar .info {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.4rem;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-secondary);
}
.quota-bar .track {
  height: 7px;
  border-radius: 7px;
  background: rgba(0, 0, 0, 0.06);
  box-shadow: var(--shadow-inset);
  overflow: hidden;
}
.quota-bar .fill {
  height: 100%;
  border-radius: 7px;
  transition: width 0.6s var(--ease-out);
}
.quota-bar .fill.normal  { background: var(--accent); box-shadow: 0 0 8px rgba(0, 122, 255, 0.3); }
.quota-bar .fill.warning { background: var(--warning); box-shadow: 0 0 8px rgba(255, 149, 0, 0.3); }
.quota-bar .fill.danger  { background: var(--danger); box-shadow: 0 0 8px rgba(255, 59, 48, 0.3); }

/* ==============================================
   Badges
   ============================================== */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-full);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  line-height: 1;
}
.badge.active    { background: var(--success-bg); color: #248A3D; }
.badge.suspended { background: var(--danger-bg); color: #D63026; }
.badge.admin     { background: var(--warning-bg); color: #C47A00; }
.badge.user      { background: var(--accent-glass); color: #0066D6; }

/* ==============================================
   Tabs
   ============================================== */

.tabs {
  display: flex;
  gap: 0.25rem;
  padding: 0.3rem;
  background: rgba(0, 0, 0, 0.04);
  border-radius: var(--radius-full);
  margin-bottom: 1.75rem;
  width: fit-content;
}
.tab {
  padding: 0.6rem 1.4rem;
  color: var(--text-tertiary);
  cursor: pointer;
  border-radius: var(--radius-full);
  font-weight: 600;
  font-size: 0.86rem;
  background: transparent;
  transition:
    all var(--duration-fast) var(--ease-out);
  white-space: nowrap;
}
.tab:hover { color: var(--text-primary); }
.tab.active {
  background: #FFFFFF;
  color: var(--text-primary);
  box-shadow: var(--shadow-xs);
  font-weight: 700;
}

/* ==============================================
   Toast
   ============================================== */

.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: #1C1C1E;
  color: #FFFFFF;
  font-weight: 700;
  font-size: 0.88rem;
  padding: 0.8rem 1.6rem;
  border-radius: var(--radius-full);
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.18),
    0 2px 8px rgba(0, 0, 0, 0.10);
  z-index: 1000;
  letter-spacing: -0.01em;
  animation: toast-in 0.35s var(--ease-spring);
}
.toast.error {
  background: var(--danger);
  color: #FFF;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(12px) scale(0.95); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}

/* ==============================================
   Modal — Floating Frosted Glass Sheet
   ============================================== */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.18);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  animation: fade-in 0.2s var(--ease-out);
}

.modal-box {
  background: var(--bg-card);
  backdrop-filter: blur(60px) saturate(1.6);
  -webkit-backdrop-filter: blur(60px) saturate(1.6);
  border: 1px solid var(--stroke-inner);
  outline: 1px solid var(--stroke-outer);
  outline-offset: -2px;
  border-radius: var(--radius-2xl);
  box-shadow: var(--shadow-xl);
  padding: 2.25rem;
  min-width: 440px;
  max-width: 90vw;
  max-height: 88vh;
  overflow-y: auto;
  animation: modal-in 0.35s var(--ease-spring);
}

.modal-box h2 {
  font-size: 1.3rem;
  font-weight: 800;
  margin-bottom: 0.5rem;
}

@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(20px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ==============================================
   Auth Pages — Centered Frosted Card
   ============================================== */

.auth-page {
  max-width: 440px;
  margin: 4rem auto;
}

.auth-page h1 {
  text-align: center;
  font-size: 2rem;
  font-weight: 900;
  letter-spacing: -0.04em;
  margin-bottom: 1.5rem;
}

.auth-page .links {
  text-align: center;
  margin-top: 1.25rem;
  font-size: 0.9rem;
  color: var(--text-tertiary);
}

/* ==============================================
   API Key Display
   ============================================== */

.api-key-display {
  background: rgba(0, 0, 0, 0.03);
  border: 1px solid rgba(0, 0, 0, 0.06);
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
  font-family: var(--font-mono);
  font-size: 0.88rem;
  word-break: break-all;
  color: var(--text-primary);
  margin: 0.5rem 0;
}
.api-key-warning {
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--danger);
  margin-top: 0.5rem;
}

/* ==============================================
   Pagination
   ============================================== */

.pagination {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  align-items: center;
  margin-top: 1.25rem;
}

/* ==============================================
   Code Blocks
   ============================================== */

pre {
  background: rgba(0, 0, 0, 0.03);
  border: 1px solid rgba(0, 0, 0, 0.06);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-inset);
  color: var(--text-primary);
  margin: 0;
  overflow-x: auto;
  padding: 1rem 1.25rem;
  white-space: pre-wrap;
  font-size: 0.85rem;
  line-height: 1.6;
}

/* ==============================================
   Utility Classes
   ============================================== */

.muted       { color: var(--text-tertiary); }
.text-center { text-align: center; }
.mt1 { margin-top: 0.75rem; }
.mt2 { margin-top: 1.5rem;  }
.mb1 { margin-bottom: 1rem; }

.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--text-tertiary);
  font-weight: 500;
}

.loading {
  opacity: 0.5;
  pointer-events: none;
  transition: opacity var(--duration-fast) var(--ease-out);
}

/* ==============================================
   Scrollbar — Subtle & Native-like
   ============================================== */

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.12);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.20);
}

/* ==============================================
   Selection
   ============================================== */

::selection {
  background: rgba(0, 122, 255, 0.20);
  color: var(--text-primary);
}

/* ==============================================
   Responsive
   ============================================== */

@media (max-width: 860px) {
  .shell { padding: 1.5rem 0; }
  .header { flex-direction: column; align-items: flex-start; }
  .tabs { overflow-x: auto; width: 100%; }
  .modal-box { min-width: auto; width: calc(100vw - 2rem); padding: 1.5rem; }
  .grid2, .grid3, .grid4 { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
}
