:root {
  --color-bg: #f4f6f9;
  --color-surface: #ffffff;
  --color-border: #dfe4ea;
  --color-text: #1f2733;
  --color-muted: #667085;
  --color-primary: #2258d8;
  --color-primary-dark: #1a45ac;
  --color-success: #16794b;
  --color-warning: #9a6700;
  --color-danger: #c0392b;
  --color-info: #0b6bcb;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.1);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
}

.hidden { display: none !important; }
.muted { color: var(--color-muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.9em; }

/* Login */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.login-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px;
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.login-card h1 { margin: 0; font-size: 22px; }
.login-card label { font-weight: 600; font-size: 14px; margin-top: 8px; }
.login-card input { padding: 10px; border: 1px solid var(--color-border); border-radius: 6px; font-size: 15px; }
.error-text { color: var(--color-danger); min-height: 1.2em; font-size: 14px; }

/* Topbar / layout */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-brand { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.brand-title { font-weight: 700; font-size: 18px; }
.topbar-status { display: flex; align-items: center; gap: 10px; }
.nav-toggle { display: none; }

.layout { display: flex; min-height: calc(100vh - 57px); }

.side-nav {
  width: 220px;
  flex-shrink: 0;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  padding: 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.nav-item {
  text-align: left;
  padding: 10px 12px;
  border: none;
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  color: var(--color-text);
}
.nav-item:hover { background: var(--color-bg); }
.nav-item.active { background: var(--color-primary); color: #fff; font-weight: 600; }

.content { flex: 1; padding: 20px; max-width: 1100px; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Cards */
.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 20px; }
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.card-label { font-size: 13px; color: var(--color-muted); }
.card-value { font-size: 22px; font-weight: 700; }

.panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 16px;
}
.panel-header { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; }

/* Buttons */
.btn {
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 14px;
  cursor: pointer;
  font-weight: 600;
}
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-secondary { background: var(--color-bg); border-color: var(--color-border); color: var(--color-text); }
.btn-ghost { background: transparent; border-color: var(--color-border); color: var(--color-text); }
.btn-success { background: #e6f4ea; color: var(--color-success); border-color: #b7e0c4; }
.btn-warning { background: #fff4e0; color: var(--color-warning); border-color: #f3d9a5; }
.btn-danger { background: #fbe9e7; color: var(--color-danger); border-color: #f0bab2; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-small { padding: 5px 10px; font-size: 12.5px; }

/* Status pills / badges */
.status-pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 600; }
.status-unknown { background: #eef0f3; color: var(--color-muted); }
.status-online { background: #e6f4ea; color: var(--color-success); }
.status-offline { background: #fbe9e7; color: var(--color-danger); }
.badge { padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-info { background: #e6f0fd; color: var(--color-info); }

/* Destinations */
.destinations-list { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.destination-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}
.destination-card.disabled { opacity: 0.6; }
.destination-order {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.destination-order .pos { font-weight: 700; font-size: 13px; color: var(--color-muted); }
.destination-main { flex: 1; min-width: 180px; }
.destination-name { font-weight: 700; }
.destination-phone { color: var(--color-muted); font-size: 14px; }
.destination-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

select.availability-select { padding: 6px 8px; border-radius: 6px; border: 1px solid var(--color-border); }

/* Forms */
.settings-form, .destinationForm { display: flex; flex-direction: column; gap: 8px; max-width: 520px; }
.settings-form label { font-weight: 600; font-size: 14px; margin-top: 6px; }
.settings-form input, .settings-form textarea, .settings-form select,
#destinationForm input, #destinationForm select {
  padding: 9px 10px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: 14px;
  width: 100%;
}
.form-row { display: flex; gap: 16px; }
.form-row > div { flex: 1; }
.save-confirm { color: var(--color-success); font-size: 14px; margin-left: 10px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.checkbox-row input { width: auto; }

/* Filters */
.filters-form { display: flex; gap: 10px; flex-wrap: wrap; margin: 14px 0; align-items: center; }
.filters-form input, .filters-form select { padding: 8px 10px; border: 1px solid var(--color-border); border-radius: 6px; }

/* Tables */
.table-wrap { overflow-x: auto; margin-top: 10px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--color-border); white-space: nowrap; }
th { color: var(--color-muted); font-weight: 600; font-size: 12.5px; text-transform: uppercase; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: var(--color-bg); }

.pagination { display: flex; gap: 8px; align-items: center; margin-top: 12px; }

/* Simulator */
.simulator-start-form { display: flex; gap: 10px; margin: 14px 0; flex-wrap: wrap; }
.simulator-start-form input { padding: 9px 10px; border: 1px solid var(--color-border); border-radius: 6px; min-width: 220px; }
.sim-current-dial { background: #fff8e6; border: 1px solid #f3d9a5; border-radius: 6px; padding: 12px; margin: 12px 0; }
.sim-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.sim-outcome { padding: 12px; border-radius: 6px; margin: 12px 0; font-weight: 600; }
.sim-outcome.connected { background: #e6f4ea; color: var(--color-success); }
.sim-outcome.callback { background: #eaf1fd; color: var(--color-info); }
.sim-skipped { margin: 6px 0 0; padding-left: 18px; color: var(--color-muted); font-size: 14px; }

/* Modals */
.modal {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.45);
  display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50;
}
.modal-card {
  background: var(--color-surface); border-radius: var(--radius); padding: 22px;
  width: 100%; max-width: 420px; box-shadow: var(--shadow);
}
.modal-wide { max-width: 720px; max-height: 85vh; overflow-y: auto; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

/* Toast */
.toast {
  position: fixed; top: 16px; right: 16px; z-index: 100;
  background: #1f2733; color: #fff; padding: 10px 16px; border-radius: 6px;
  font-size: 14px; box-shadow: var(--shadow); opacity: 0; pointer-events: none;
  transition: opacity 0.2s ease;
}
.toast.show { opacity: 1; }
.toast.toast-error { background: var(--color-danger); }
.toast.toast-success { background: var(--color-success); }

/* Responsive */
@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .side-nav {
    width: 100%; flex-direction: row; overflow-x: auto; border-right: none;
    border-bottom: 1px solid var(--color-border); display: none;
  }
  .side-nav.open { display: flex; }
  .nav-toggle { display: inline-block; }
  .content { padding: 14px; }
}

@media (max-width: 600px) {
  .card-grid { grid-template-columns: 1fr 1fr; }
  .form-row { flex-direction: column; gap: 8px; }
  .destination-card { flex-direction: column; align-items: stretch; }
  .destination-controls { justify-content: space-between; }
  table { font-size: 13px; }
}
#tab-live .card { margin: 1rem 0; padding: 1rem; overflow-x: auto; }
#tab-live label { display: block; margin: .65rem 0; }
#tab-live textarea { display: block; width: 100%; min-height: 4rem; }
#weeklyHours > div { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
#tab-live table { width: 100%; }
#tab-live th, #tab-live td { padding: .6rem; text-align: left; }
#tab-forwarding .card { padding: 1rem; margin: 1rem 0; overflow-x: auto; }
#tab-forwarding label { display: block; margin: .8rem 0; }
#tab-forwarding textarea { display: block; width: 100%; min-height: 4rem; }
#forwardingHours > div { display: flex; gap: .8rem; flex-wrap: wrap; }
#busyXml { white-space: pre-wrap; overflow-wrap: anywhere; }
#forwardedCalls td, #forwardedCalls th { padding: .6rem; text-align: left; }
