:root {
  --bg: #0f1419;
  --panel: #161c24;
  --panel-2: #1d2630;
  --line: #2a3542;
  --text: #e6edf3;
  --muted: #8b98a5;
  --accent: #2f81f7;
  --accent-2: #1f6feb;
  --green: #2ea043;
  --code-bg: #0b0f14;
  --danger: #f85149;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

code, pre, .code { font-family: "SF Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo {
  font-weight: 800;
  letter-spacing: .5px;
  background: linear-gradient(135deg, var(--accent), #8957e5);
  color: #fff;
  padding: 10px 12px;
  border-radius: var(--radius);
  font-size: 16px;
}
.app-header h1 { font-size: 17px; margin: 0; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; }
.header-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Layout */
.layout {
  display: grid;
  grid-template-columns: minmax(420px, 1fr) minmax(420px, 1fr);
  gap: 0;
  height: calc(100vh - 64px);
}
.editor, .preview { overflow: auto; padding: 18px 20px; }
.editor { border-right: 1px solid var(--line); }
.preview { background: var(--panel); display: flex; flex-direction: column; padding-top: 0; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  .editor { border-right: none; border-bottom: 1px solid var(--line); }
}

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tab {
  background: none; border: none; color: var(--muted);
  padding: 10px 14px; cursor: pointer; font-size: 13.5px; font-weight: 600;
  border-bottom: 2px solid transparent;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

.panel { display: none; }
.panel.active { display: block; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

h2 { font-size: 14px; margin: 18px 0 10px; color: var(--text); }
.hint { color: var(--muted); font-size: 12.5px; margin: 0 0 14px; }
.help-link { color: var(--accent); text-decoration: none; }
.help-link:hover { text-decoration: underline; }
.hint code, label code { color: #b9c4d0; background: var(--panel-2); padding: 1px 5px; border-radius: 5px; font-size: 11.5px; }

/* Forms */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
@media (max-width: 560px) { .grid2, .grid3 { grid-template-columns: 1fr; } }

label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 12.5px; }
input, select {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 13px;
  width: 100%;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }
input[type="checkbox"] { width: auto; }

/* Cards */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px; gap: 10px;
}
.card-title { font-weight: 700; font-size: 13px; }
.badge {
  font-size: 11px; color: #cdd9e5; background: var(--panel-2);
  border: 1px solid var(--line); padding: 2px 8px; border-radius: 999px;
}
.collapse-fields { margin-top: 10px; }
.muted-row { color: var(--muted); font-size: 12px; }

/* Buttons */
.btn {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
.btn.primary:hover { background: var(--accent); }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); }

/* Preview */
.file-tabs { position: sticky; top: 0; background: var(--panel); padding-top: 14px; z-index: 2; margin-bottom: 0; }
.file-toolbar { display: flex; align-items: center; gap: 8px; padding: 10px 0; }
.file-name { font-size: 12.5px; color: var(--muted); }
.spacer { flex: 1; }
.code {
  background: var(--code-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  overflow: auto;
  flex: 1;
  font-size: 12.5px;
  white-space: pre;
  margin: 0;
}
.code code { color: #c9d6e2; }

.toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  background: var(--green); color: #fff; padding: 10px 16px; border-radius: 8px;
  font-size: 13px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 50;
}
.toast.show { opacity: 1; }

/* PBX picker in header */
.storage-status { font-size: 11.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.storage-status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.storage-status.file::before { background: var(--green); }
.storage-status.browser::before { background: #d29922; }
.storage-status.error::before { background: var(--danger); }
.pbx-pick { flex-direction: row; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.pbx-pick select { width: auto; min-width: 160px; }
.sep { width: 1px; height: 24px; background: var(--line); margin: 0 4px; }

/* Preview head */
.preview-head { display: flex; align-items: center; padding: 12px 0 6px; position: sticky; top: 0; background: var(--panel); z-index: 3; }
.preview-title { font-weight: 700; font-size: 13px; }

/* Panel head with actions */
.panel-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Tables */
.tbl { width: 100%; border-collapse: collapse; font-size: 12.5px; margin-top: 8px; }
.tbl th, .tbl td { text-align: left; padding: 8px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl th { color: var(--muted); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; }
.tbl tr:hover td { background: var(--panel-2); }
.tbl input, .tbl select { padding: 6px 8px; font-size: 12.5px; }
.tbl .row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.tbl td.num { color: var(--muted); width: 28px; }
.empty { color: var(--muted); font-size: 12.5px; padding: 16px 0; }

/* Chips */
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; padding: 2px 9px; font-size: 11.5px; display: flex; align-items: center; gap: 6px; }
.chip button { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 13px; line-height: 1; padding: 0; }
.chip button:hover { color: var(--danger); }

/* Device list */
.dev-row .name { font-weight: 700; }
.dev-row .mac { font-family: ui-monospace, monospace; color: var(--muted); font-size: 11.5px; }
.active-dev td { background: rgba(47,129,247,.12) !important; }

/* Lines list inside device editor */
.line-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; align-items: end; margin-bottom: 8px; }
.dect-handset-card { margin-bottom: 12px; }
.dect-acct-block { margin-top: 10px; }
.dect-acct-block .field-label { font-size: 12px; font-weight: 600; margin-bottom: 4px; }
.dect-acct-checks { display: flex; flex-wrap: wrap; gap: 8px 14px; margin-top: 6px; }
.check-inline { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; cursor: pointer; user-select: none; }
.check-inline input { margin: 0; }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; z-index: 40; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; width: min(560px, 92vw); max-height: 86vh; overflow: auto; }
.modal h3 { margin: 0 0 12px; font-size: 15px; }
.modal .modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
textarea { background: var(--panel-2); border: 1px solid var(--line); color: var(--text); border-radius: 8px; padding: 10px; font-family: ui-monospace, monospace; font-size: 12px; width: 100%; min-height: 140px; }

.subtle { color: var(--muted); font-size: 12px; }
.divider { height: 1px; background: var(--line); margin: 18px 0; }
.section-title { display: flex; align-items: center; justify-content: space-between; margin: 16px 0 8px; }
.section-title h2 { margin: 0; }
