:root {
  --bg: #0f1115;
  --panel: #161a22;
  --panel-2: #1d2230;
  --border: #2a3142;
  --text: #e6e9ef;
  --muted: #8b93a7;
  --accent: #4f8cff;
  --accent-hover: #6aa1ff;
  --green: #25c685;
  --red: #ff5470;
  --yellow: #f5b54a;
  --gray: #6b7385;
  --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 8px 24px rgba(0,0,0,0.18);
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
}

a { color: var(--accent); }
code { background: var(--panel-2); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
hr { border: none; border-top: 1px solid var(--border); margin: 18px 0; }

/* ===== Top bar ===== */
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 20px; border-bottom: 1px solid var(--border);
  background: var(--panel); position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand .logo { font-size: 20px; }
.brand .title { font-weight: 600; }
.brand .subtitle { color: var(--muted); margin-left: 4px; font-size: 12px; }
.tabs { margin-left: auto; display: flex; gap: 4px; }
.tab {
  background: transparent; border: none; color: var(--muted); padding: 8px 14px;
  border-radius: 6px; cursor: pointer; font-size: 13px;
}
.tab:hover { color: var(--text); background: var(--panel-2); }
.tab.active { background: var(--panel-2); color: var(--text); }

.status { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); margin-left: 8px; }
.dot { width: 8px; height: 8px; border-radius: 50%; }
.dot-green { background: var(--green); box-shadow: 0 0 6px var(--green); }
.dot-red { background: var(--red); box-shadow: 0 0 6px var(--red); }
.dot-yellow { background: var(--yellow); box-shadow: 0 0 6px var(--yellow); }
.dot-gray { background: var(--gray); }

/* ===== Layout ===== */
main { padding: 20px; }
.view { display: none; }
.view.active { display: block; }

.panel {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
}
.panel + .panel { margin-top: 18px; }
.panel-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.panel-header h2, .panel-header h3 { margin: 0; font-size: 14px; font-weight: 600; }

/* ===== Dialer view ===== */
.dialer-grid {
  display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 18px;
}
.dialer-controls { display: flex; align-items: center; gap: 10px; }
.now-calling {
  background: linear-gradient(135deg, #1f2a4a, #16223a);
  border: 1px solid #2c3d6b; border-radius: var(--radius);
  padding: 16px; margin-top: 12px;
}
.now-calling-label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; }
.now-calling-name { font-size: 18px; font-weight: 600; margin-top: 2px; }
.now-calling-phone { color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.now-calling-controls { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.call-timer { font-family: ui-monospace, monospace; font-size: 16px; margin-left: auto; }

.outcome-row { display: flex; gap: 8px; align-items: center; margin-top: 12px; flex-wrap: wrap; }
.outcome-row label { color: var(--muted); font-size: 12px; }
.outcome-row select, .outcome-row input {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  padding: 6px 8px; border-radius: 6px; font-size: 13px;
}
.outcome-row input { flex: 1; min-width: 180px; }

.manual-call { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.manual-call input {
  flex: 1; background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  padding: 8px 10px; border-radius: 6px;
}
.dialpad {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; max-width: 220px; margin-top: 10px;
}
.dialpad button {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  padding: 12px 0; border-radius: 8px; font-size: 16px; cursor: pointer;
}
.dialpad button:hover { background: #28304a; }
.dialpad button:active { background: var(--accent); }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.stat {
  background: var(--panel-2); border-radius: 8px; padding: 12px;
  text-align: center; border: 1px solid var(--border);
}
.stat-num { font-size: 22px; font-weight: 600; }
.stat-label { color: var(--muted); font-size: 11px; margin-top: 2px; text-transform: uppercase; letter-spacing: 0.05em; }

.recent-list { max-height: 360px; overflow-y: auto; }
.recent-item {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 8px 6px; border-bottom: 1px solid var(--border);
}
.recent-item:last-child { border-bottom: none; }
.recent-item .who { font-weight: 500; }
.recent-item .meta { color: var(--muted); font-size: 12px; }

/* ===== Contacts table ===== */
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar input, .toolbar select {
  background: var(--panel); color: var(--text); border: 1px solid var(--border);
  padding: 8px 10px; border-radius: 6px; font-size: 13px;
}
.toolbar input[type=search] { min-width: 280px; }
.toolbar .grow { flex: 1; }
.table-wrap {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
}
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 13px; }
.table th { background: var(--panel-2); color: var(--muted); font-weight: 500; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }
.table tr:hover td { background: var(--panel-2); }
.table .row-actions { display: flex; gap: 4px; justify-content: flex-end; }

.pill { font-size: 11px; padding: 2px 8px; border-radius: 999px; text-transform: uppercase; letter-spacing: 0.04em; }
.pill-gray { background: #2a3142; color: #b6bdce; }
.pill-green { background: rgba(37,198,133,0.15); color: var(--green); }
.pill-yellow { background: rgba(245,181,74,0.15); color: var(--yellow); }
.pill-red { background: rgba(255,84,112,0.15); color: var(--red); }
.pill-blue { background: rgba(79,140,255,0.15); color: var(--accent); }

/* ===== Buttons ===== */
.btn {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  padding: 8px 14px; border-radius: 6px; cursor: pointer; font-size: 13px;
  display: inline-flex; align-items: center; gap: 6px;
  text-decoration: none;
}
.btn:hover { border-color: #3a4358; background: #232a3b; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { background: rgba(255,84,112,0.15); color: var(--red); border-color: rgba(255,84,112,0.3); }
.btn-danger:hover { background: rgba(255,84,112,0.25); }
.btn-success { background: rgba(37,198,133,0.15); color: var(--green); border-color: rgba(37,198,133,0.3); }
.btn-tiny { padding: 4px 8px; font-size: 11px; }
.icon-btn { background: transparent; border: none; color: var(--muted); cursor: pointer; font-size: 16px; }
.icon-btn:hover { color: var(--text); }

.hint { color: var(--muted); font-size: 12px; }
.hint code { font-size: 11px; }

/* ===== Calls list ===== */
.calls-list { display: grid; gap: 10px; }
.call-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center;
}
.call-card .who { font-weight: 600; }
.call-card .meta { color: var(--muted); font-size: 12px; }
.call-card .right { text-align: right; }
.call-card .duration { font-family: ui-monospace, monospace; color: var(--accent); }

/* The HTML `hidden` attribute normally hides elements, but any explicit
   `display: ...` rule wins by specificity (UA stylesheet loses). Add
   `!important` here so `.modal[hidden]`, `.toast[hidden]`,
   `.now-calling[hidden]` etc. actually hide. */
[hidden] { display: none !important; }

/* ===== Modal ===== */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.55); display: flex;
  align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  width: 100%; max-width: 560px; padding: 18px; box-shadow: var(--shadow); max-height: 90vh; overflow: auto;
}
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.modal-header h2 { margin: 0; font-size: 16px; }

.contact-form, .settings-form { display: grid; gap: 10px; }
.contact-form label, .settings-form label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
.contact-form input, .contact-form textarea, .contact-form select,
.settings-form input {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  padding: 8px 10px; border-radius: 6px; font-size: 13px; font-family: inherit;
}
.row { display: flex; gap: 8px; align-items: center; justify-content: flex-end; }

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--border); padding: 10px 16px;
  border-radius: 8px; box-shadow: var(--shadow); z-index: 200; max-width: 70vw;
}
.toast.success { border-color: rgba(37,198,133,0.4); }
.toast.error { border-color: rgba(255,84,112,0.4); color: var(--red); }

/* ===== Misc ===== */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #2a3142; border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: #3a4358; }

@media (max-width: 900px) {
  .dialer-grid { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
}
