/* izenphone admin — Nairobi Console */
:root {
  --ink: #07140f;
  --ink-2: #0c1f17;
  --ink-3: #143126;
  --panel: rgba(255, 252, 247, 0.88);
  --panel-solid: #fffcf7;
  --line: rgba(15, 45, 32, 0.1);
  --line-strong: rgba(15, 45, 32, 0.18);
  --muted: #5d6f66;
  --text: #13261d;
  --accent: #12b76a;
  --accent-deep: #0b7a45;
  --accent-soft: rgba(18, 183, 106, 0.12);
  --amber: #d97706;
  --amber-soft: rgba(217, 119, 6, 0.12);
  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, 0.1);
  --sky: #0284c7;
  --sky-soft: rgba(2, 132, 199, 0.12);
  --radius: 18px;
  --shadow: 0 18px 50px rgba(7, 20, 15, 0.08);
  --shadow-sm: 0 8px 24px rgba(7, 20, 15, 0.06);
  --font-display: "Fraunces", "Times New Roman", serif;
  --font-ui: "Outfit", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font-ui);
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(18, 183, 106, 0.18), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(217, 119, 6, 0.12), transparent 50%),
    linear-gradient(165deg, #eef6f1 0%, #f6f1e8 48%, #e8f2ec 100%);
  background-attachment: fixed;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.32;
  z-index: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.45'/%3E%3C/svg%3E");
  mix-blend-mode: soft-light;
}

#gate, #app, dialog { position: relative; z-index: 1; }

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

/* Login */
#gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

/* Must beat #gate { display:grid } — otherwise login stays visible after sign-in */
#gate.hidden {
  display: none !important;
}

#login-form {
  width: min(420px, 100%);
  padding: 36px 32px;
  border-radius: 28px;
  background: rgba(255, 252, 247, 0.94);
  border: 1px solid rgba(255, 255, 255, 0.7);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
  animation: rise 0.55s ease both;
}

#login-form h1 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.02em;
  font-size: 1.85rem;
}

#login-kicker {
  color: var(--accent-deep) !important;
  letter-spacing: 0.16em !important;
  font-size: 0.72rem !important;
}

#login-form input {
  border-radius: 14px !important;
  border-color: var(--line-strong) !important;
  background: #fff;
  transition: border-color 0.2s, box-shadow 0.2s;
}

#login-form input:focus {
  outline: none;
  border-color: var(--accent) !important;
  box-shadow: 0 0 0 4px var(--accent-soft);
}

#login-form button[type="submit"],
#login-form > button.w-full {
  border-radius: 14px !important;
  background: linear-gradient(135deg, var(--accent), var(--accent-deep)) !important;
  box-shadow: 0 10px 24px rgba(11, 122, 69, 0.28);
  transition: transform 0.15s ease, filter 0.15s ease;
}

#login-form button[type="submit"]:hover,
#login-form > button.w-full:hover {
  filter: brightness(1.05);
  transform: translateY(-1px);
}

/* App shell */
#app {
  display: grid;
  grid-template-columns: 268px 1fr;
  min-height: 100vh;
}

#app.hidden { display: none !important; }

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  width: auto;
  float: none;
  display: flex;
  flex-direction: column;
  background:
    linear-gradient(180deg, rgba(18, 183, 106, 0.12), transparent 28%),
    linear-gradient(165deg, var(--ink) 0%, var(--ink-2) 55%, #0a1a14 100%);
  border-right: 1px solid rgba(255, 255, 255, 0.06);
  box-shadow: 12px 0 40px rgba(7, 20, 15, 0.18);
}

.sidebar > div:first-child { padding: 28px 22px 18px !important; }

#nav-kicker {
  color: #6ee7a8 !important;
  letter-spacing: 0.22em !important;
}

#nav-title {
  font-family: var(--font-display) !important;
  font-weight: 600 !important;
  letter-spacing: -0.02em;
  font-size: 1.35rem !important;
}

#whoami {
  color: rgba(148, 163, 184, 0.9) !important;
  line-height: 1.4;
}

.sidebar nav {
  padding: 8px 12px !important;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  overflow: auto;
}

.nav-btn {
  width: 100%;
  text-align: left;
  color: #b7c7be;
  padding: 11px 14px;
  border-radius: 14px;
  font-size: 14px;
  font-weight: 500;
  border: 0;
  background: transparent;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease;
}

.nav-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
}

.nav-active {
  background: linear-gradient(135deg, rgba(18, 183, 106, 0.95), rgba(11, 122, 69, 0.95)) !important;
  color: #fff !important;
  box-shadow: 0 8px 20px rgba(18, 183, 106, 0.28);
}

#logout {
  margin: 12px 16px 22px !important;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.03);
  transition: background 0.15s, color 0.15s;
}

#logout:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff !important;
}

.main-pane {
  margin-left: 0;
  padding: 28px 32px 56px;
  min-height: 100vh;
  animation: rise 0.45s ease both;
}

#page-title {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.03em;
  font-size: 2rem !important;
  color: var(--ink);
}

#page-sub { color: var(--muted) !important; }

.lang-btn,
.store-chip,
#refresh {
  border: 1px solid var(--line-strong);
  background: rgba(255, 252, 247, 0.9);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s ease;
  box-shadow: var(--shadow-sm);
}

.lang-btn:hover,
.store-chip:hover,
#refresh:hover {
  border-color: var(--accent);
  color: var(--accent-deep);
}

.lang-btn.active,
.store-chip.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-deep));
  color: #fff;
  border-color: transparent;
  box-shadow: 0 8px 18px rgba(11, 122, 69, 0.25);
}

.card {
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.65);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 20px;
  backdrop-filter: blur(10px);
  transition: box-shadow 0.2s ease;
}

.card:hover { box-shadow: var(--shadow); }

.stat {
  position: relative;
  overflow: hidden;
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.72), rgba(255, 252, 247, 0.92));
}

.stat::after {
  content: "";
  position: absolute;
  right: -20px;
  top: -20px;
  width: 90px;
  height: 90px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--accent-soft), transparent 70%);
}

.stat p:nth-child(2),
.stat .text-2xl,
.stat .text-xl {
  font-family: var(--font-display) !important;
  letter-spacing: -0.03em;
  color: var(--ink);
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: rgba(238, 246, 241, 0.95);
  color: var(--muted);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-align: left;
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
}

td {
  text-align: left;
  padding: 14px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

tbody tr { transition: background 0.15s ease; }
tbody tr:hover { background: rgba(18, 183, 106, 0.04); }
tbody tr:last-child td { border-bottom: 0; }

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.badge.bg-emerald-100 { background: var(--accent-soft) !important; color: var(--accent-deep) !important; }
.badge.bg-amber-100 { background: var(--amber-soft) !important; color: #92400e !important; }
.badge.bg-red-100 { background: var(--danger-soft) !important; color: #991b1b !important; }
.badge.bg-sky-100 { background: var(--sky-soft) !important; color: #075985 !important; }
.badge.bg-slate-100,
.badge.bg-slate-200 { background: rgba(15, 45, 32, 0.08) !important; color: var(--muted) !important; }
.badge.bg-violet-100 { background: rgba(124, 58, 237, 0.1) !important; color: #5b21b6 !important; }

#view input[type="text"],
#view input[type="number"],
#view input[type="password"],
#view input[type="email"],
#view input[type="date"],
#view input:not([type]),
#view select,
#view textarea,
.card input,
.card select,
.card textarea {
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: #fff;
  padding: 8px 12px;
  font-family: var(--font-ui);
  transition: border-color 0.15s, box-shadow 0.15s;
}

#view input:focus,
#view select:focus,
#view textarea:focus,
.card input:focus,
.card select:focus,
.card textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

#view button.bg-brand-600,
.card button.bg-brand-600,
button.rounded-lg.bg-brand-600 {
  background: linear-gradient(135deg, var(--accent), var(--accent-deep)) !important;
  border: 0;
  box-shadow: 0 8px 18px rgba(11, 122, 69, 0.22);
  transition: transform 0.15s ease, filter 0.15s ease;
}

#view button.bg-brand-600:hover,
button.rounded-lg.bg-brand-600:hover {
  filter: brightness(1.05);
  transform: translateY(-1px);
}

#view button.rounded-lg.border,
.card button.rounded-lg.border {
  border: 1px solid var(--line-strong) !important;
  background: rgba(255, 252, 247, 0.9);
}

#view button.rounded-lg.border:hover {
  border-color: var(--accent) !important;
  color: var(--accent-deep);
}

#view a.text-brand-600,
button.text-brand-600 {
  color: var(--accent-deep) !important;
  font-weight: 600;
}

.finance-metric .metric-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.finance-metric .metric-value {
  font-family: var(--font-display);
  font-size: 1.65rem;
  font-weight: 600;
  letter-spacing: -0.03em;
  margin-top: 6px;
  color: var(--ink);
}

.finance-metric .metric-hint {
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
  line-height: 1.4;
}

.toast {
  margin-bottom: 16px;
  border-radius: 14px;
  padding: 12px 14px;
  background: var(--accent-soft);
  color: var(--accent-deep);
  border: 1px solid rgba(18, 183, 106, 0.25);
  font-weight: 600;
  animation: rise 0.25s ease both;
}

.toast.error {
  background: var(--danger-soft);
  color: #991b1b;
  border-color: rgba(220, 38, 38, 0.25);
}

dialog#drawer {
  border: 0;
  border-radius: 24px;
  padding: 0;
  width: min(860px, 96vw);
  box-shadow: 0 30px 80px rgba(7, 20, 15, 0.28);
  background: var(--panel-solid);
}

dialog#drawer::backdrop {
  background: rgba(7, 20, 15, 0.45);
  backdrop-filter: blur(4px);
}

#drawer-title {
  font-family: var(--font-display);
  font-size: 1.25rem;
  letter-spacing: -0.02em;
}

#drawer-close {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

#drawer-close:hover {
  background: var(--accent-soft);
  color: var(--accent-deep);
}

.card.border-amber-200,
.card.bg-amber-50 {
  background: linear-gradient(135deg, #fffbeb, #fff7ed) !important;
  border-color: rgba(217, 119, 6, 0.25) !important;
}

#kphone-ai-fab {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 60;
  width: 56px;
  height: 56px;
  border-radius: 18px;
  border: 0;
  background: linear-gradient(145deg, var(--ink-2), var(--ink));
  color: #fff;
  font-weight: 800;
  box-shadow: 0 14px 34px rgba(7, 20, 15, 0.35);
  transition: transform 0.18s ease;
}

#kphone-ai-fab:hover { transform: translateY(-2px) scale(1.03); }
#kphone-ai-fab.hidden-fab {
  transform: scale(0.4);
  opacity: 0;
  pointer-events: none;
}

#kphone-ai.ai-hidden { display: none; }

#kphone-ai-panel {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 70;
  width: min(380px, 100vw);
  height: 100vh;
  background: linear-gradient(180deg, var(--ink-2), var(--ink));
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  transform: translateX(110%);
  transition: transform 0.22s ease;
  box-shadow: -16px 0 40px rgba(0, 0, 0, 0.25);
}

#kphone-ai-panel.open { transform: translateX(0); }

.ai-head, .ai-toolbar, .ai-form, .ai-chip { padding: 14px 16px; }

.ai-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.ai-kicker {
  font-size: 10px;
  letter-spacing: 0.18em;
  color: #6ee7a8;
}

.ai-head h2 {
  font-family: var(--font-display);
  font-size: 18px;
  margin-top: 4px;
}

.ai-head button, .ai-toolbar button, .ai-form button {
  border: 0;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 12px;
  cursor: pointer;
}

.ai-head button { background: transparent; color: #94a3b8; }
.ai-toolbar { display: flex; gap: 8px; }
.ai-toolbar button { background: #1e293b; color: #e2e8f0; }
.ai-toolbar button.active { background: var(--accent); color: #fff; }

.ai-chip {
  margin: 0 16px;
  border-radius: 10px;
  background: #111827;
  font-size: 12px;
  color: #94a3b8;
}

.ai-chip.has-target {
  color: #bbf7d0;
  background: #064e3b;
}

.ai-log {
  flex: 1;
  overflow: auto;
  padding: 8px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ai-msg {
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.ai-msg.user {
  background: var(--accent);
  color: #fff;
  align-self: flex-end;
  max-width: 92%;
}

.ai-msg.assistant {
  background: #1e293b;
  align-self: flex-start;
  max-width: 92%;
}

.ai-form { border-top: 1px solid rgba(255, 255, 255, 0.08); }

.ai-form textarea {
  width: 100%;
  border-radius: 12px;
  border: 1px solid #334155;
  background: #020617;
  color: #fff;
  padding: 10px;
  resize: none;
}

.ai-form button {
  margin-top: 8px;
  width: 100%;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.ai-hover {
  outline: 2px dashed #34d399 !important;
  outline-offset: 3px;
  cursor: copy;
}

.ai-selected {
  outline: 3px solid var(--accent) !important;
  outline-offset: 3px;
  box-shadow: 0 0 0 4px rgba(18, 183, 106, 0.18);
}

body.ai-picking { cursor: crosshair; }
body.ai-panel-open .main-pane { padding-right: min(400px, 42vw); }

/* Compact docs dropdown in customer table */
.docs-menu {
  position: relative;
  display: inline-block;
  min-width: 7.5rem;
}

.docs-menu-btn {
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
  user-select: none;
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.2;
  border: 1px solid transparent;
  white-space: nowrap;
}

.docs-menu-btn::-webkit-details-marker { display: none; }

.docs-menu-btn.ready {
  color: #047857;
  background: rgba(16, 185, 129, 0.12);
  border-color: rgba(16, 185, 129, 0.28);
}

.docs-menu-btn.partial {
  color: #b45309;
  background: rgba(245, 158, 11, 0.12);
  border-color: rgba(245, 158, 11, 0.3);
}

.docs-menu-caret {
  font-size: 0.65rem;
  opacity: 0.75;
  transition: transform 0.15s ease;
}

.docs-menu[open] .docs-menu-caret { transform: rotate(180deg); }

.docs-menu-panel {
  position: absolute;
  z-index: 40;
  top: calc(100% + 6px);
  left: 0;
  min-width: 13.5rem;
  padding: 0.45rem;
  border-radius: 14px;
  background: var(--panel-solid);
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow-sm);
  display: grid;
  gap: 0.35rem;
}

.docs-menu-item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.4rem 0.5rem;
  border-radius: 10px;
  border: 1px solid rgba(16, 185, 129, 0.22);
  background: rgba(16, 185, 129, 0.06);
  color: #065f46;
  text-decoration: none;
  font-size: 0.72rem;
  line-height: 1.25;
}

.docs-menu-item:hover { background: rgba(16, 185, 129, 0.12); }

.docs-menu-item.missing {
  border-color: rgba(245, 158, 11, 0.35);
  background: rgba(245, 158, 11, 0.08);
  color: #92400e;
}

.docs-menu-thumb {
  width: 2rem;
  height: 2rem;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
  border: 1px solid rgba(15, 45, 32, 0.12);
  background: #fff;
}

.docs-menu-thumb.pdf,
.docs-menu-thumb.empty {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.58rem;
  font-weight: 700;
  color: #065f46;
  background: #ecfdf5;
}

.docs-menu-thumb.empty {
  color: #92400e;
  background: #fffbeb;
}

.docs-menu-item .muted { color: #b45309; }
.docs-menu-item .linkish { color: #047857; text-decoration: underline; }

.customer-actions {
  min-width: 8.5rem;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
  vertical-align: top;
}

table td { vertical-align: middle; }
table td.customer-actions { vertical-align: top; padding-top: 0.75rem; padding-bottom: 0.75rem; }

@media (max-width: 960px) {
  #app { grid-template-columns: 1fr; }

  .sidebar {
    position: relative;
    height: auto;
    box-shadow: none;
  }

  .sidebar nav {
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 12px !important;
  }

  .nav-btn {
    white-space: nowrap;
    width: auto;
    flex: 0 0 auto;
  }

  .main-pane { padding: 18px 16px 40px; }
  #page-title { font-size: 1.55rem !important; }
  body.ai-panel-open .main-pane { padding-right: 16px; }
  #kphone-ai-panel { width: 100vw; }
}
