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

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

:root {
  --bg:          #151323;
  --bg-2:        #1c1a2e;
  --surface:     rgba(255,255,255,0.06);
  --surface-hov: rgba(255,255,255,0.10);

  --primary:       #d48a4a;
  --primary-light: #f0a96a;
  --primary-dark:  #b56b32;
  --primary-glow:  rgba(212,138,74,0.25);

  --accent:      #8b5cf6;
  --accent-glow: rgba(139,92,246,0.2);

  --text:         #f4f0ec;
  --text-muted:   #a09a94;
  --text-subtle:  #6e6860;

  --border:       rgba(255,255,255,0.12);
  --border-focus: rgba(212,138,74,0.5);

  --danger:      #ef4444;
  --danger-glow: rgba(239,68,68,0.2);
  --success:     #22c55e;
  --success-glow:rgba(34,197,94,0.18);
  --warning:     #f59e0b;

  --radius:    12px;
  --radius-sm: 8px;
  --radius-lg: 16px;

  --blur: blur(20px);
  --ease: cubic-bezier(0.16, 1, 0.3, 1);

  --sidebar-w: 240px;
}

/* ===== BASE ===== */
html, body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  min-height: 100vh;
  background-image:
    radial-gradient(ellipse 70% 45% at 15% 0%, rgba(212,138,74,0.10) 0%, transparent 55%),
    radial-gradient(ellipse 55% 38% at 85% 100%, rgba(139,92,246,0.09) 0%, transparent 55%);
}

/* ===== SIDEBAR ===== */
.sidebar {
  width: var(--sidebar-w);
  background: linear-gradient(180deg, #201d32 0%, #17152a 100%);
  border-right: 1px solid var(--border);
  padding: 1.25rem 0.75rem;
  position: fixed;
  height: 100vh;
  overflow-y: auto;
  z-index: 100;
  display: flex;
  flex-direction: column;
}

.sidebar h1 {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 1.75rem;
  padding: 0.875rem 1rem;
  color: var(--primary-light);
  letter-spacing: -0.02em;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(212,138,74,0.12);
  background: rgba(212,138,74,0.06);
}

.sidebar ul {
  list-style: none;
  flex: 1;
}

.sidebar li {
  margin-bottom: 2px;
}

.sidebar a {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.65rem 0.875rem;
  color: var(--text-muted);
  text-decoration: none;
  border-radius: var(--radius-sm);
  transition: all 0.18s var(--ease);
  font-size: 0.88rem;
  font-weight: 500;
  position: relative;
  white-space: nowrap;
  overflow: hidden;
}

.sidebar a:hover {
  background: var(--surface-hov);
  color: var(--text);
  transform: translateX(2px);
}

.sidebar a.active {
  background: linear-gradient(135deg, rgba(212,138,74,0.15), rgba(212,138,74,0.07));
  color: var(--primary-light);
  border: 1px solid rgba(212,138,74,0.2);
}

.sidebar a[href="/api/logout"] {
  color: var(--text-subtle);
  margin-top: 0.5rem;
}

.sidebar a[href="/api/logout"]:hover {
  color: #f87171;
  background: rgba(239,68,68,0.1);
}

/* ===== MAIN CONTENT ===== */
.content {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 2rem 2rem 2rem;
  min-width: 0;
}

.content h1 {
  font-size: 1.625rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
  letter-spacing: -0.03em;
  color: var(--text);
}

.content h2 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-top: 2rem;
  margin-bottom: 0.875rem;
  color: var(--text);
  letter-spacing: -0.02em;
}

.content h3 {
  font-size: 0.95rem;
  font-weight: 600;
  margin-top: 0.875rem;
  margin-bottom: 0.5rem;
}

/* ===== DASHBOARD GRID ===== */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

/* ===== CARDS ===== */
.card {
  background: rgba(255,255,255,0.04);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.375rem;
  transition: all 0.2s var(--ease);
  cursor: default;
  position: relative;
  overflow: hidden;
}

.card::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  background: linear-gradient(135deg, rgba(255,255,255,0.06) 0%, transparent 60%);
  pointer-events: none;
}

.card:hover {
  border-color: rgba(212,138,74,0.22);
  background: rgba(255,255,255,0.06);
  transform: translateY(-2px);
  box-shadow: 0 12px 40px rgba(0,0,0,0.35), 0 0 0 1px rgba(212,138,74,0.08);
}

.card h3 {
  font-size: 0.67rem;
  color: var(--text-muted);
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.09em;
  margin-bottom: 0.625rem;
  margin-top: 0;
}

.card .number {
  font-size: 1.875rem;
  font-weight: 700;
  color: var(--primary-light);
  letter-spacing: -0.03em;
  word-break: break-word;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

/* ===== FORM CONTAINER ===== */
.form-container {
  background: rgba(255,255,255,0.03);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.375rem;
  margin-bottom: 1.5rem;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 0.875rem;
  margin-bottom: 1.125rem;
}

.form-grid > div {
  display: flex;
  flex-direction: column;
}

.form-group {
  margin-bottom: 0.875rem;
}

label {
  display: block;
  font-size: 0.775rem;
  font-weight: 500;
  margin-bottom: 0.35rem;
  color: var(--text-muted);
  letter-spacing: 0.01em;
}

input, textarea, select {
  width: 100%;
  padding: 0.6rem 0.875rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-family: inherit;
  transition: all 0.18s var(--ease);
  background: rgba(255,255,255,0.04);
  color: var(--text);
  -webkit-appearance: none;
  appearance: none;
  -webkit-tap-highlight-color: transparent;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  background: rgba(255,255,255,0.06);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

input:disabled, textarea:disabled, select:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

input::placeholder {
  color: var(--text-subtle);
}

select {
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a847e' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  background-size: 1rem 1rem;
  padding-right: 2.25rem;
  cursor: pointer;
}

select option {
  background: #1a1828;
  color: var(--text);
}

textarea {
  min-height: 96px;
  resize: vertical;
}

/* ===== BUTTONS ===== */
button, .btn {
  padding: 0.575rem 1.125rem;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.18s var(--ease);
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  letter-spacing: 0.01em;
  font-family: inherit;
}

button[type="submit"],
.btn-primary {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: #fff;
  box-shadow: 0 2px 14px var(--primary-glow);
}

button[type="submit"]:hover,
.btn-primary:hover {
  background: linear-gradient(135deg, var(--primary-light) 0%, var(--primary) 100%);
  transform: translateY(-1px);
  box-shadow: 0 4px 22px rgba(212,138,74,0.38);
}

button[type="submit"]:active,
.btn-primary:active {
  transform: scale(0.97);
  box-shadow: 0 1px 8px var(--primary-glow);
}

.btn-secondary {
  background: var(--surface-hov);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: rgba(255,255,255,0.1);
  border-color: rgba(255,255,255,0.14);
}

.btn-danger {
  background: rgba(239,68,68,0.12);
  color: #f87171;
  border: 1px solid rgba(239,68,68,0.22);
}

.btn-danger:hover {
  background: rgba(239,68,68,0.22);
  box-shadow: 0 2px 14px var(--danger-glow);
}

.btn-success {
  background: rgba(34,197,94,0.12);
  color: #4ade80;
  border: 1px solid rgba(34,197,94,0.22);
}

.btn-success:hover {
  background: rgba(34,197,94,0.22);
}

/* ===== TABLES ===== */
.table-wrapper {
  overflow-x: auto;
  margin-bottom: 1.5rem;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.025);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 100%;
}

th, td {
  padding: 0.7rem 0.875rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  background: rgba(255,255,255,0.025);
  font-weight: 600;
  font-size: 0.68rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.09em;
  position: sticky;
  top: 0;
  z-index: 10;
}

tr:last-child td {
  border-bottom: none;
}

tr {
  transition: background 0.15s var(--ease);
}

tr:hover td {
  background: rgba(255,255,255,0.025);
}

td {
  font-size: 0.875rem;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

td button {
  padding: 0.3rem 0.65rem;
  font-size: 0.78rem;
  min-height: 32px;
  margin-right: 0.25rem;
  border-radius: 6px;
}

td button:last-child {
  margin-right: 0;
}

/* ===== LOGIN PAGE ===== */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  width: 100%;
  background:
    radial-gradient(ellipse 80% 60% at 50% 10%, rgba(212,138,74,0.14) 0%, transparent 58%),
    radial-gradient(ellipse 55% 40% at 80% 90%, rgba(139,92,246,0.09) 0%, transparent 55%),
    var(--bg);
  padding: 1rem;
}

.login-form {
  background: rgba(255,255,255,0.05);
  backdrop-filter: blur(28px);
  -webkit-backdrop-filter: blur(28px);
  border: 1px solid rgba(255,255,255,0.1);
  padding: 2.5rem;
  border-radius: var(--radius-lg);
  box-shadow: 0 32px 80px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.08);
  width: 100%;
  max-width: 380px;
  animation: slideUp 0.38s var(--ease) both;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(28px); }
  to   { opacity: 1; transform: translateY(0); }
}

.login-form h1 {
  font-size: 2.25rem;
  margin-bottom: 0.3rem;
  text-align: center;
  background: linear-gradient(135deg, var(--primary-light) 0%, var(--primary) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.04em;
}

.login-form .subtitle {
  text-align: center;
  color: var(--text-muted);
  margin-bottom: 1.75rem;
  font-size: 0.875rem;
}

.login-form input {
  margin-bottom: 1rem;
}

.login-form button {
  width: 100%;
  padding: 0.875rem;
  font-size: 1rem;
  margin-bottom: 1rem;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: #fff;
  box-shadow: 0 4px 28px var(--primary-glow);
}

.login-form button:hover {
  box-shadow: 0 6px 36px rgba(212,138,74,0.42);
  transform: translateY(-1px);
}

.login-form .hint {
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-subtle);
}

/* ===== MOBILE NAV ===== */
.mobile-nav {
  display: none;
}

/* ===== TABLET (768px) ===== */
@media (max-width: 768px) {
  :root { --sidebar-w: 60px; }

  .sidebar {
    width: var(--sidebar-w);
    padding: 1rem 0.25rem;
    align-items: center;
  }

  .sidebar h1 {
    font-size: 1.4rem;
    padding: 0.5rem;
    text-align: center;
    margin-bottom: 1.25rem;
    white-space: nowrap;
    overflow: hidden;
    border: none;
    background-color: transparent;
    /* gradient clipping on just the emoji */
  }

  .sidebar a {
    justify-content: center;
    padding: 0.75rem 0.375rem;
    gap: 0;
  }

  .sidebar .nav-label { display: none; }
  .sidebar .nav-icon  { font-size: 1.3rem; }

  .content {
    margin-left: var(--sidebar-w);
    padding: 1.5rem 1.25rem;
  }

  .dashboard-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .form-grid {
    grid-template-columns: 1fr;
  }
}

/* ===== PHONE (480px) ===== */
@media (max-width: 480px) {
  html { font-size: 14px; }

  body {
    display: block;
    padding-bottom: 72px;
  }

  .sidebar { display: none; }

  .content {
    margin-left: 0;
    padding: 1rem;
  }

  .content h1  { font-size: 1.3rem; margin-bottom: 1rem; }
  .content h2  { font-size: 1rem; margin-top: 1.25rem; margin-bottom: 0.75rem; }

  .dashboard-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.625rem;
    margin-bottom: 1.25rem;
  }

  .card { padding: 0.875rem; border-radius: var(--radius-sm); }
  .card h3 { font-size: 0.6rem; margin-bottom: 0.5rem; }
  .card .number { font-size: 1.3rem; }

  .form-container { padding: 1rem; margin-bottom: 1rem; }
  .form-grid { grid-template-columns: 1fr; gap: 0.625rem; margin-bottom: 0.875rem; }

  label { font-size: 0.75rem; }

  input, textarea, select {
    font-size: 16px; /* prevents iOS zoom */
    padding: 0.625rem 0.75rem;
  }

  button, .btn {
    font-size: 0.9rem;
    padding: 0.75rem;
    min-height: 48px;
  }

  th { font-size: 0.62rem; }
  td { font-size: 0.8rem; }
  th, td { padding: 0.5rem 0.5rem; }

  .table-wrapper { margin-bottom: 1rem; }

  /* ====== MOBILE BOTTOM NAV ====== */
  .mobile-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 64px;
    background: rgba(18, 16, 28, 0.96);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border-top: 1px solid var(--border);
    z-index: 1000;
    box-shadow: 0 -8px 40px rgba(0,0,0,0.45);
    justify-content: space-around;
    align-items: center;
    padding: 0 0.125rem;
  }

  .mobile-nav a {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    color: var(--text-muted);
    font-size: 1.35rem;
    transition: all 0.16s var(--ease);
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    min-height: 64px;
    border-radius: var(--radius-sm);
    position: relative;
  }

  .mobile-nav a.active {
    color: var(--primary-light);
  }

  .mobile-nav a.active::after {
    content: '';
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--primary);
  }

  .mobile-nav a:active {
    color: var(--primary-light);
    background: rgba(212,138,74,0.1);
    transform: scale(0.88);
  }

  @supports (padding: max(0px)) {
    .mobile-nav {
      padding-bottom: max(0px, env(safe-area-inset-bottom));
      height: calc(64px + env(safe-area-inset-bottom));
    }
    body {
      padding-bottom: calc(72px + env(safe-area-inset-bottom));
    }
  }

  .login-form { padding: 1.75rem 1.5rem; }
}

/* ===== UTILITIES ===== */
.text-center { text-align: center; }
.text-muted   { color: var(--text-muted); }
.text-danger  { color: #f87171; }
.text-success { color: #4ade80; }
.mt { margin-top: 1rem; }
.mb { margin-bottom: 1rem; }

/* Scrollbar */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.18); }

/* Selection */
::selection { background: var(--primary-glow); color: var(--primary-light); }

/* Focus ring */
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 4px; }

/* Touch targets */
@media (hover: none) and (pointer: coarse) {
  button, a { min-height: 48px; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
