:root {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #1d2733;
  background: #f3f6f9;
  line-height: 1.5;
  --blue: #1769e0;
  --blue-dark: #0f55bb;
  --border: #dbe2ea;
  --muted: #667485;
  --green: #15803d;
  --red: #c62828;
  --amber: #a16207;
}

* { box-sizing: border-box; }

body { min-width: 320px; min-height: 100vh; margin: 0; }
button, input, select { font: inherit; }
.hidden { display: none !important; }

.topbar {
  min-height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 28px;
  color: #fff;
  background: #182430;
}

.brand { display: flex; align-items: baseline; gap: 14px; }
.brand strong { font-size: 20px; }
.brand span { color: #aeb9c5; }

.connection-status { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.connection-status i { width: 9px; height: 9px; border-radius: 50%; background: #e0a325; }
.connection-status i.online { background: #36be72; }
.connection-status i.error { background: #e05252; }
.connection-status strong { padding: 3px 7px; border-radius: 5px; background: #ffffff18; }

.icon { width: 20px; height: 20px; flex: 0 0 auto; display: block; pointer-events: none; }
.button-with-icon { display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.button-with-icon:not(.secondary) > .icon, .topbar-icon-button > .icon { filter: brightness(0) invert(1); }
.icon-button { width: 56px; min-width: 56px; height: 56px; min-height: 56px; display: inline-grid; place-items: center; padding: 0; border-radius: 10px; }
.topbar-icon-button { width: 36px; min-width: 36px; height: 36px; min-height: 36px; display: inline-grid; place-items: center; padding: 0; border: 1px solid #ffffff40; border-radius: 9px; background: #ffffff12; }
.topbar-icon-button:hover { border-color: #ef8c8c; background: var(--red); }

.loginbar { padding: 24px; border-bottom: 1px solid var(--border); background: #fff; }
.login-form { max-width: 780px; display: grid; grid-template-columns: 1fr 1fr auto; align-items: end; gap: 12px; margin: auto; }

label { display: grid; gap: 6px; color: #536170; font-size: 13px; font-weight: 650; }
input { width: 100%; min-height: 42px; padding: 9px 11px; border: 1px solid #b9c4cf; border-radius: 7px; color: inherit; background: #fff; outline: none; }
select { width: 100%; min-height: 42px; padding: 9px 34px 9px 11px; border: 1px solid #b9c4cf; border-radius: 7px; color: inherit; background: #fff; }
input:focus, select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px #1769e026; outline: none; }

button { min-height: 42px; padding: 9px 14px; border: 0; border-radius: 7px; color: #fff; background: var(--blue); cursor: pointer; font-weight: 700; }
button:hover { background: var(--blue-dark); }
button:disabled { cursor: not-allowed; opacity: .45; }
button.secondary { color: #233344; background: #e9eff6; }
button.secondary:hover { background: #dce6f0; }
button.success { background: var(--green); }
button.success:hover { background: #116b33; }
button.danger { background: var(--red); }
button.danger:hover { background: #a91f1f; }

.tabs { display: flex; overflow-x: auto; padding: 0 24px; border-bottom: 1px solid var(--border); background: #fff; }
.tab { min-height: 58px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 0 20px; border-bottom: 3px solid transparent; border-radius: 0; color: #526171; background: transparent; white-space: nowrap; }
.tab .icon { width: 18px; height: 18px; }
.tab:hover { color: var(--blue-dark); background: #f7f9fb; }
.tab.active { border-color: var(--blue); color: var(--blue-dark); background: transparent; }
.counter { min-width: 20px; display: inline-grid; place-items: center; margin-left: 5px; padding: 1px 5px; border-radius: 999px; color: #fff; background: var(--red); font-size: 11px; }

main { max-width: 1440px; margin: 28px auto; padding: 0 24px 48px; }
.tab-panel:not(.active) { display: none; }

.card { overflow: hidden; border: 1px solid var(--border); border-radius: 12px; background: #fff; box-shadow: 0 4px 16px #1c355708; }
.card > header { min-height: 70px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 15px 18px; border-bottom: 1px solid var(--border); }
h1, h2 { margin: 0; font-size: 21px; }
.badge { width: max-content; padding: 5px 9px; border-radius: 999px; color: var(--muted); background: #edf2f7; font-size: 12px; font-weight: 700; }
.status-badge, .form-message { display: inline-flex; align-items: center; gap: 6px; }
.status-icon { width: 16px; height: 16px; flex: 0 0 auto; }
.status-badge.critical { color: #fff; background: var(--red); }
.status-badge.warning { color: #6d5000; background: #ffe7a3; }
.status-badge.success { color: #176b35; background: #e2f5e8; }
.status-badge.critical .status-icon, .form-message.critical .status-icon { filter: brightness(0) invert(1); }

.incoming { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 18px; padding: 16px 18px; border: 2px solid #63b17c; border-radius: 10px; background: #effaf2; }
.incoming div:first-child { display: grid; }
.incoming strong { font-size: 17px; }
.incoming span { font-weight: 700; }
.incoming small { color: var(--muted); }
.button-row { display: flex; flex-wrap: wrap; gap: 8px; }

.call-layout { display: grid; grid-template-columns: minmax(320px, 460px) minmax(0, 1fr); align-items: start; gap: 18px; }
.dialer { padding: 0 18px 18px; }
.dialer > header { margin-right: -18px; margin-left: -18px; }
.dialer > label { margin-top: 16px; }
.target-row { display: grid; grid-template-columns: minmax(0, 1fr) 56px; align-items: stretch; gap: 8px; }
.target { min-height: 56px; font-size: 25px; font-weight: 750; text-align: center; }
.primary-actions, .call-controls { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 14px; }
.primary-actions button { min-height: 50px; }

.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.key { min-height: 58px; display: grid; place-items: center; padding: 5px; border: 1px solid var(--border); color: #233344; background: #f7f9fb; font-size: 20px; }
.key:hover { background: #e8f1fd; }
.key small { color: var(--muted); font-size: 9px; font-weight: 500; letter-spacing: .1em; }
.call-controls { padding-top: 14px; border-top: 1px solid var(--border); }
.transfer-form { display: grid; gap: 10px; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }
.transfer-form .button-row { display: grid; grid-template-columns: 1fr 1fr; }

.video-card { padding-bottom: 16px; }
.videos { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; padding: 16px; }
figure { min-width: 0; margin: 0; }
video { width: 100%; aspect-ratio: 16/9; display: block; border-radius: 8px; background: #111820; object-fit: cover; }
figcaption { margin-top: 5px; color: var(--muted); font-size: 12px; }
.notice { margin: 0 16px; padding: 10px 12px; border-radius: 7px; color: #66500d; background: #fff3d2; font-size: 12px; }
audio { display: none; }

.inline-form { display: grid; grid-template-columns: 1fr 1fr auto; align-items: end; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.form-message { min-height: 22px; margin: 10px 18px; color: var(--muted); font-size: 13px; }
.form-message.warning { width: fit-content; padding: 7px 9px; border-radius: 7px; color: #6d5000; background: #fff3d2; }
.form-message.critical { width: fit-content; padding: 7px 9px; border-radius: 7px; color: #fff; background: var(--red); }
.form-message.success { color: var(--green); }
.blf-list { display: grid; gap: 10px; padding: 0 18px 18px; }
.empty { padding: 36px; border: 1px dashed #bfc9d4; border-radius: 9px; color: var(--muted); text-align: center; }
.blf-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 9px; }
.blf-item.free { border-color: #bcd8c5; background: #effaf2; }
.blf-item.busy { border-color: #efc2c2; background: #fdf0f0; }
.blf-name, .blf-state { display: block; }
.blf-name { font-weight: 750; }
.blf-state { color: var(--muted); font-size: 12px; }
.blf-actions { display: flex; gap: 7px; }
.blf-actions button { min-height: 36px; padding: 7px 10px; }

.messages-layout { min-height: 580px; display: grid; grid-template-columns: 310px minmax(0, 1fr); }
.threads { border-right: 1px solid var(--border); }
.new-thread { display: grid; grid-template-columns: 1fr auto; gap: 7px; padding: 12px; border-bottom: 1px solid var(--border); }
.thread-list { display: grid; gap: 4px; padding: 8px; }
.thread { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; padding: 10px; border: 1px solid transparent; border-radius: 7px; color: inherit; background: transparent; text-align: left; }
.thread:hover { background: #f2f6fa; }
.thread.active { border-color: #c6daf6; background: #e8f1fd; }
.thread strong, .thread small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread small { color: var(--muted); font-weight: 400; }
.conversation { min-width: 0; display: flex; flex-direction: column; }
.conversation-head { min-height: 59px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.conversation-head button { min-height: 34px; padding: 6px 10px; }
.message-list { flex: 1; display: flex; flex-direction: column; gap: 9px; padding: 16px; overflow: auto; background: #f7f9fb; }
.message { max-width: min(78%, 680px); padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: #fff; overflow-wrap: anywhere; }
.message.in { align-self: flex-start; border-top-left-radius: 3px; }
.message.out { align-self: flex-end; border-color: #bcd8c5; border-top-right-radius: 3px; background: #effaf2; }
.message time { display: block; margin-top: 4px; color: var(--muted); font-size: 10px; text-align: right; }
.composer { display: grid; grid-template-columns: 1fr auto; gap: 8px; padding: 12px; border-top: 1px solid var(--border); }

.call-history-card { padding-bottom: 18px; }
.call-history-actions { display: flex; align-items: center; gap: 8px; }
.call-history-actions button { min-height: 34px; padding: 6px 10px; }
.call-history-tools { display: grid; grid-template-columns: minmax(220px, 1.4fr) minmax(150px, .8fr) minmax(190px, 1fr); gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--border); background: #f8fafc; }
.call-history-list { display: grid; gap: 7px; padding: 0 18px; }
.call-history-row { display: grid; grid-template-columns: minmax(150px, 1.5fr) minmax(120px, 1fr) minmax(160px, 1fr) minmax(90px, .7fr); align-items: center; gap: 12px; min-height: 52px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; }
.call-history-head { min-height: auto; border: 0; border-bottom: 1px solid var(--border); border-radius: 0; color: var(--muted); font-size: 12px; font-weight: 750; }
.call-history-peer { min-width: 0; display: flex; align-items: center; gap: 9px; font-weight: 750; }
.call-history-peer span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.call-history-direction { display: flex; align-items: center; gap: 7px; }
.call-history-direction .icon { width: 18px; height: 18px; }
.call-history-direction.missed { color: var(--red); font-weight: 700; }
.call-history-time { color: #3d4d5d; }
.call-history-duration { font-variant-numeric: tabular-nums; font-weight: 700; }

.settings-card { padding-bottom: 18px; }
.facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 18px; }
.facts div { padding: 14px; border: 1px solid var(--border); border-radius: 8px; }
.facts dt { color: var(--muted); font-size: 12px; }
.facts dd { margin: 5px 0 0; overflow-wrap: anywhere; font-weight: 700; }
.settings-card > .button-row { margin: 0 18px 14px; }
.settings-note { margin: 0 18px 14px; padding: 11px 13px; border-radius: 7px; color: #66500d; background: #fff3d2; font-size: 13px; }
.settings-note code { font-weight: 800; }
pre { min-height: 240px; margin: 0 18px; padding: 14px; overflow: auto; border-radius: 8px; color: #d6e1eb; background: #111820; font: 12px/1.5 ui-monospace, Consolas, monospace; white-space: pre-wrap; }

@media (max-width: 980px) {
  .call-layout { grid-template-columns: 1fr; }
  .messages-layout { grid-template-columns: 1fr; }
  .threads { border-right: 0; border-bottom: 1px solid var(--border); }
  .thread-list { max-height: 240px; overflow: auto; }
  .call-history-head { display: none; }
  .call-history-row { grid-template-columns: minmax(0, 1fr) auto; }
  .call-history-time, .call-history-duration { font-size: 12px; }
  .call-history-duration { text-align: right; }
  .facts { grid-template-columns: 1fr; }
}

@media (max-width: 680px) {
  .topbar, .incoming { align-items: stretch; flex-direction: column; padding: 14px 16px; }
  .brand span { display: none; }
  .login-form, .inline-form { grid-template-columns: 1fr; }
  .tabs { padding: 0; }
  .tab { padding: 0 14px; }
  main { margin-top: 18px; padding: 0 10px 30px; }
  .videos { grid-template-columns: 1fr; }
  .message { max-width: 92%; }
  .call-history-card > header { align-items: flex-start; flex-direction: column; }
  .call-history-actions { width: 100%; justify-content: space-between; }
  .call-history-tools { grid-template-columns: 1fr; padding: 12px 10px; }
  .call-history-list { padding: 0 10px; }
  .call-history-row { grid-template-columns: 1fr; gap: 5px; }
  .call-history-duration { text-align: left; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
}
