@import 'tailwindcss/theme' layer(theme);
@import 'tailwindcss/preflight' layer(base);
@import 'tailwindcss/utilities' layer(utilities);

/* ── Oracle Dark Premium Theme (in theme layer) ── */
@layer theme {
  :root, html.light {
    --bg: #f4f2ef; --bg1: #ffffff; --bg2: #faf9f7; --bg3: #efeee9; --bg4: #e5e3dd;
    --bd: #ddd9d2; --bdf: #c5c0b8;
    --t1: #1c1917; --t2: #44403c; --t3: #78716c; --t4: #a8a29e;
    --ac: #c74634; --ach: #b13d2e; --acd: #9a3427; --acl: rgba(199,70,52,.06); --acl2: rgba(199,70,52,.1);
    --gn: #16a34a; --gnl: rgba(22,163,74,.08); --rd: #dc2626; --rdl: rgba(220,38,38,.06);
    --bl: #2563eb; --bll: rgba(37,99,235,.06); --yl: #ca8a04; --yll: rgba(202,138,4,.06);
    --pp: #7c3aed; --ppl: rgba(124,58,237,.06);
    --ok: #16a34a; --w: #ca8a04; --err: #dc2626;
    --r: 12px; --rl: 16px; --rr: 20px;
    --sh1: 0 1px 2px rgba(28,25,23,.04), 0 1px 3px rgba(28,25,23,.06);
    --sh2: 0 4px 6px -1px rgba(28,25,23,.05), 0 2px 4px -2px rgba(28,25,23,.04);
    --sh3: 0 10px 15px -3px rgba(28,25,23,.06), 0 4px 6px -4px rgba(28,25,23,.04);
    --shh: 0 20px 25px -5px rgba(28,25,23,.08), 0 8px 10px -6px rgba(28,25,23,.04);
    --tb-bg: rgba(255,255,255,.8);
    --fm: 'JetBrains Mono', monospace;
    --fs: 'Plus Jakarta Sans', -apple-system, system-ui, sans-serif;
    --trans: cubic-bezier(.22,1,.36,1);
  }

  html.dark {
    --bg: #0d0f14; --bg1: #151820; --bg2: #1a1e28; --bg3: #222733; --bg4: #2a3040;
    --bd: #2a3040; --bdf: #3a4258;
    --t1: #f0f0f4; --t2: #c8cad0; --t3: #8b8fa3; --t4: #5a5e6e;
    --ac: #c74634; --ach: #d9523f; --acd: #a83428; --acl: rgba(199,70,52,.1); --acl2: rgba(199,70,52,.16);
    --gn: #34c759; --gnl: rgba(52,199,89,.1); --rd: #ff453a; --rdl: rgba(255,69,58,.1);
    --bl: #0a84ff; --bll: rgba(10,132,255,.1); --yl: #ffd60a; --yll: rgba(255,214,10,.1);
    --pp: #bf5af2; --ppl: rgba(191,90,242,.1);
    --ok: #34c759; --w: #ffd60a; --err: #ff453a;
    --sh1: 0 1px 3px rgba(0,0,0,.3), 0 1px 2px rgba(0,0,0,.2);
    --sh2: 0 4px 8px rgba(0,0,0,.3), 0 2px 4px rgba(0,0,0,.2);
    --sh3: 0 10px 20px rgba(0,0,0,.35), 0 4px 8px rgba(0,0,0,.2);
    --shh: 0 20px 30px rgba(0,0,0,.4), 0 8px 12px rgba(0,0,0,.25);
    --tb-bg: rgba(21,24,32,.85);
  }
}

/* ── Base resets (in base layer) ── */
@layer base {
  *, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
  body {
    font-family: var(--fs);
    background: var(--bg);
    color: var(--t1);
    height: 100vh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
  }
  ::selection { background: rgba(199,70,52,.2); color: var(--t1); }

  html.light *, html.dark * {
    transition: background-color .25s var(--trans), border-color .25s var(--trans), color .15s var(--trans);
  }

  ::-webkit-scrollbar { width: 6px; height: 6px; }
  ::-webkit-scrollbar-track { background: transparent; }
  ::-webkit-scrollbar-thumb { background: var(--bd); border-radius: 3px; }
  ::-webkit-scrollbar-thumb:hover { background: var(--bdf); }

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

  /* Form elements */
  select {
    appearance: none;
    background: var(--bg1) 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='%2378716c' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E") no-repeat right 12px center;
    border: 1px solid var(--bd);
    border-radius: var(--r);
    padding: 9px 36px 9px 14px;
    font-size: .82rem;
    font-family: var(--fs);
    color: var(--t1);
    cursor: pointer;
    transition: border-color .2s, box-shadow .2s;
    min-width: 0;
  }
  select:focus {
    outline: none;
    border-color: var(--ac);
    box-shadow: 0 0 0 3px var(--acl);
  }
  select:hover { border-color: var(--bdf); }

  input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="search"],
  textarea {
    background: var(--bg1);
    border: 1px solid var(--bd);
    border-radius: var(--r);
    padding: 9px 14px;
    font-size: .82rem;
    font-family: var(--fs);
    color: var(--t1);
    transition: border-color .2s, box-shadow .2s;
    width: 100%;
  }
  input[type="text"]:focus, input[type="email"]:focus, input[type="password"]:focus,
  input[type="number"]:focus, input[type="search"]:focus, textarea:focus {
    outline: none;
    border-color: var(--ac);
    box-shadow: 0 0 0 3px var(--acl);
  }

  input[type="checkbox"] {
    appearance: none;
    width: 18px;
    height: 18px;
    border: 2px solid var(--bd);
    border-radius: 5px;
    background: var(--bg1);
    cursor: pointer;
    transition: all .15s;
    flex-shrink: 0;
    position: relative;
  }
  input[type="checkbox"]:checked {
    background: var(--ac);
    border-color: var(--ac);
  }
  input[type="checkbox"]:checked::after {
    content: '';
    position: absolute;
    left: 4px;
    top: 1px;
    width: 6px;
    height: 10px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
  }
}

/* ── Component styles — OUTSIDE layers so they override Tailwind utilities ── */

/* Nav item hover */
nav a:hover { background: var(--bg3); color: var(--t1) !important; }

/* Page wrapper */
.page {
  padding: 28px 32px;
  max-width: 1280px;
  animation: fadeIn .35s ease;
}
.page-full {
  height: 100%;
  animation: fadeIn .35s ease;
}

/* Page header */
.page-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 24px;
}
.page-header h1 {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--t1);
  letter-spacing: -.01em;
}
.page-header .subtitle {
  font-size: .8rem;
  color: var(--t3);
  margin-top: 2px;
}
.page-header .spacer { flex: 1; }
.page-header .count {
  font-size: .75rem;
  font-weight: 600;
  color: var(--t3);
  background: var(--bg3);
  padding: 4px 12px;
  border-radius: 20px;
}

/* Cards */
.card {
  background: var(--bg1);
  border: 1px solid var(--bd);
  border-radius: var(--rl);
  box-shadow: var(--sh1);
  padding: 20px 24px;
  margin-bottom: 16px;
}
.card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--bd);
}
.card-header h2 {
  font-size: .92rem;
  font-weight: 700;
  color: var(--t1);
}
.card-header .icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* Tables */
.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: .82rem;
}
.data-table thead th {
  text-align: left;
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--t3);
  padding: 10px 14px;
  background: var(--bg2);
  border-bottom: 1px solid var(--bd);
}
.data-table thead th:first-child { border-radius: var(--r) 0 0 0; }
.data-table thead th:last-child { border-radius: 0 var(--r) 0 0; }
.data-table tbody td {
  padding: 12px 14px;
  color: var(--t2);
  border-bottom: 1px solid var(--bg3);
  vertical-align: middle;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: var(--bg2); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--r);
  font-size: .82rem;
  font-weight: 600;
  font-family: var(--fs);
  cursor: pointer;
  border: 1px solid transparent;
  transition: all .2s var(--trans);
  white-space: nowrap;
}
.btn:disabled {
  opacity: .5;
  cursor: not-allowed;
}
.btn-primary {
  background: var(--ac);
  color: #fff;
  border-color: var(--ac);
}
.btn-primary:hover:not(:disabled) { background: var(--ach); }
.btn-secondary {
  background: var(--bg1);
  color: var(--t2);
  border-color: var(--bd);
}
.btn-secondary:hover:not(:disabled) { background: var(--bg3); color: var(--t1); }
.btn-danger {
  background: transparent;
  color: var(--rd);
  border-color: var(--rd);
}
.btn-danger:hover:not(:disabled) { background: var(--rdl); }
.btn-success {
  background: var(--gn);
  color: #fff;
  border-color: var(--gn);
}
.btn-sm {
  padding: 6px 12px;
  font-size: .75rem;
  border-radius: 8px;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: .68rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge-green { background: var(--gnl); color: var(--gn); }
.badge-red { background: var(--rdl); color: var(--rd); }
.badge-blue { background: var(--bll); color: var(--bl); }
.badge-yellow { background: var(--yll); color: var(--yl); }
.badge-purple { background: var(--ppl); color: var(--pp); }
.badge-gray { background: var(--bg3); color: var(--t3); }

/* Empty state */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
  color: var(--t4);
}
.empty-state svg { opacity: .35; margin-bottom: 12px; }
.empty-state h3 { font-size: .92rem; font-weight: 600; color: var(--t3); margin-bottom: 4px; }
.empty-state p { font-size: .78rem; }

/* KPI cards */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.kpi-card {
  background: var(--bg1);
  border: 1px solid var(--bd);
  border-radius: var(--rl);
  padding: 18px 20px;
  box-shadow: var(--sh1);
}
.kpi-card .label {
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--t3);
  margin-bottom: 8px;
}
.kpi-card .value {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--t1);
  letter-spacing: -.02em;
}
.kpi-card .sub {
  font-size: .72rem;
  color: var(--t4);
  margin-top: 4px;
}

/* Form groups */
.form-group {
  margin-bottom: 16px;
}
.form-group label {
  display: block;
  font-size: .75rem;
  font-weight: 600;
  color: var(--t2);
  margin-bottom: 6px;
}
.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

/* Tags/pills */
.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: .72rem;
  font-weight: 500;
  background: var(--bg3);
  color: var(--t2);
  border: 1px solid var(--bd);
}
.tag button {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--t3);
  padding: 0;
  font-size: .82rem;
  line-height: 1;
}
.tag button:hover { color: var(--rd); }

/* Section divider */
.section-title {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--t4);
  margin: 24px 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--bg3);
}

/* Prevent text overflow on resize */
.prose pre, .chat-markdown pre {
  overflow-x: auto;
  max-width: 100%;
}
.prose table, .chat-markdown table {
  overflow-x: auto;
  display: block;
  max-width: 100%;
}
.prose code, .chat-markdown code {
  word-break: break-all;
}
.prose p, .chat-markdown p {
  overflow-wrap: break-word;
  word-break: break-word;
}

/* Tooltip-like labels */
.field-label {
  font-size: .7rem;
  font-weight: 600;
  color: var(--t3);
  text-transform: uppercase;
  letter-spacing: .04em;
}
