:root {
  --bg: #0B101B;
  --panel: #121826;
  --panel-2: #171F31;
  --border: #243047;
  --text: #F1F5F9;
  --muted: #94A3B8;
  --emerald: #00B06F;
  --emerald-2: #10B981;
  --blue: #38BDF8;
  --gold: #FBBF24;
  --danger: #EF4444;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Segoe UI", sans-serif;
  overflow: hidden;
}

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

.app { display: flex; flex-direction: column; height: 100vh; }

/* Top Header */
.topbar {
  height: 56px;
  padding: 0 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-badge {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, #00B06F, #0284C7);
  display: grid;
  place-items: center;
  font-size: 18px;
  flex-shrink: 0;
}
.brand-title { font-size: 16px; font-weight: 800; letter-spacing: 0.3px; white-space: nowrap; }
.brand-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.nav-tabs {
  display: flex;
  gap: 6px;
  background: #0D1320;
  padding: 4px;
  border-radius: 10px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.nav-tab {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  padding: 6px 14px;
  border-radius: 7px;
  cursor: pointer;
}
.nav-tab.active {
  background: var(--panel-2);
  color: #fff;
  box-shadow: inset 0 0 0 1px #334155;
}

.top-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.api-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #0D1320;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 3px 6px 3px 9px;
}
.api-lbl { font-size: 11px; font-weight: 700; color: var(--muted); }
.api-input {
  width: 175px;
  background: transparent;
  border: none;
  outline: none;
  color: #E2E8F0;
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.btn {
  border: 1px solid #334155;
  background: #1B2437;
  color: var(--text);
  padding: 7px 12px;
  border-radius: 9px;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
}
.btn:hover { background: #232F46; }
.btn.primary { background: var(--emerald); border-color: #059669; color: #042015; }
.btn.primary:hover { background: var(--emerald-2); }
.btn.blue { background: #0284C7; border-color: #0369A1; color: #fff; }
.btn.danger { background: rgba(239,68,68,0.12); border-color: rgba(239,68,68,0.4); color: #FCA5A5; }
.btn.sm { padding: 4px 8px; font-size: 11.5px; border-radius: 6px; }

/* Main Workspace Grid */
.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: 248px minmax(420px, 1fr) 610px;
  min-height: 0;
}
.workspace.hidden, .monitor-view.hidden { display: none; }

/* Left Explorer */
.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  padding: 12px;
}
.sec-title {
  font-size: 11px;
  font-weight: 800;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin: 10px 4px 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.item-card {
  padding: 10px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color .15s, transform .1s;
}
.item-card:hover { border-color: #475569; }
.item-card.active { border-color: var(--emerald); background: rgba(0,176,111,0.1); }
.item-row { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.item-name {
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.item-sub {
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pill {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 99px;
  background: rgba(56,189,248,0.15);
  color: #7DD3FC;
  flex-shrink: 0;
}
.pill.green { background: rgba(0,176,111,0.18); color: #6EE7B7; }
.pill.gold { background: rgba(251,191,36,0.16); color: #FDE68A; }
.pill.danger { background: rgba(239,68,68,0.16); color: #FCA5A5; }

/* Center Editor + AI */
.center {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  border-right: 1px solid var(--border);
  background: #0E1422;
}
.ai-box {
  padding: 12px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.ai-input-row { display: flex; gap: 8px; }
.ai-input {
  flex: 1;
  background: #0B101B;
  border: 1px solid #334155;
  border-radius: 10px;
  color: #fff;
  padding: 9px 12px;
  font-size: 13px;
  outline: none;
}
.ai-input:focus { border-color: var(--blue); }
.ai-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; align-items: center; }
.chip {
  border: 1px solid #2C3A54;
  background: #161F31;
  color: #CBD5E1;
  font-size: 11.5px;
  padding: 4px 10px;
  border-radius: 99px;
  cursor: pointer;
}
.chip:hover { border-color: var(--blue); color: #fff; }
.model-drawer {
  margin-top: 10px;
  padding: 10px;
  border-radius: 10px;
  background: #0B101B;
  border: 1px solid #26334B;
  display: none;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}
.model-drawer.open { display: grid; }
.field-lbl { font-size: 11px; color: var(--muted); display: block; margin-bottom: 4px; }
.field-inp {
  width: 100%;
  background: #141C2E;
  border: 1px solid #334155;
  border-radius: 7px;
  color: #fff;
  padding: 6px 8px;
  font-size: 12px;
  outline: none;
}

.editor-tabs {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  height: 40px;
  background: #101726;
  border-bottom: 1px solid var(--border);
}
.etabs-left { display: flex; gap: 4px; }
.etab {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.etab.active { color: #fff; border-bottom-color: var(--emerald); }
.editor-body { flex: 1; min-height: 0; position: relative; }
.code-area {
  width: 100%;
  height: 100%;
  border: none;
  resize: none;
  outline: none;
  background: #0B0F19;
  color: #E2E8F0;
  padding: 14px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.55;
  tab-size: 2;
}
.meta-form {
  padding: 16px;
  height: 100%;
  overflow-y: auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  align-content: start;
}
.meta-form .full { grid-column: 1 / -1; }

/* Right Dual Simulator */
.sim-pane {
  background: #0B101B;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 10px 12px;
}
.sim-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.sim-phones {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.phone {
  background: #141B29;
  border: 1.5px solid #2A364F;
  border-radius: 18px;
  padding: 7px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.phone-head {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--muted);
  padding: 2px 6px 6px;
}
.phone iframe {
  flex: 1;
  width: 100%;
  border: none;
  border-radius: 12px;
  background: #0B0F19;
}
.sim-log {
  height: 112px;
  margin-top: 8px;
  background: #101624;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  font-family: ui-monospace, monospace;
  font-size: 11px;
  color: #94A3B8;
  overflow-y: auto;
  white-space: pre-wrap;
}

/* Monitor View */
.monitor-view {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  background: var(--bg);
}
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.stat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
}
.stat-val { font-size: 24px; font-weight: 800; margin-top: 6px; color: #fff; }
.table-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 16px;
  overflow-x: auto;
}
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid #1E293B; }
th { color: var(--muted); font-weight: 700; }

/* Toast */
.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 999;
  background: #1E293B;
  border: 1px solid var(--emerald);
  color: #fff;
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 700;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  display: none;
}
