/* ==========================================================
   E-send — responsive stylesheet
   Theme colors are injected as CSS variables from PHP:
   --primary, --primary-d, --side, --accent
   ========================================================== */
:root {
  --primary: #2b74c9;
  --primary-d: #1f5aa3;
  --side: #0f2440;
  --accent: #7cb342;
  --bg: #eef2f7;
  --card: #ffffff;
  --text: #1c2733;
  --muted: #5b6b7b;
  --line: #dde3ea;
  --input: #ffffff;
  --danger: #d32f2f;
  --warn: #ef8f00;
  --ok: #2e7d32;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15, 36, 64, .08), 0 6px 18px rgba(15, 36, 64, .06);
  --drawer-w: 270px;
  --topbar-h: 60px;
}
[data-theme="dark"] {
  --bg: #0e141b;
  --card: #17202a;
  --text: #e3e9ef;
  --muted: #93a3b3;
  --line: #2a3644;
  --input: #111920;
  --shadow: 0 1px 3px rgba(0, 0, 0, .4);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
}
a { color: var(--primary); text-decoration: none; }
[data-theme="dark"] a { color: color-mix(in srgb, var(--primary) 55%, #fff); }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 .6em; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.08rem; }
p { margin: 0 0 1em; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1.2rem 0; }
code, kbd { background: color-mix(in srgb, var(--primary) 12%, transparent); padding: .1em .4em; border-radius: 5px; font-size: .92em; word-break: break-all; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.text-right { text-align: right; }
.mt-0 { margin-top: 0; } .mb-0 { margin-bottom: 0; } .mt-1 { margin-top: 1rem; } .mb-1 { margin-bottom: 1rem; }
[hidden] { display: none !important; }

/* ---------- Drawer navigation ---------- */
.drawer {
  position: fixed; inset: 0 auto 0 0;
  width: var(--drawer-w); max-width: 85vw;
  background: var(--side);
  color: #e6edf5;
  display: flex; flex-direction: column;
  z-index: 50;
  transform: translateX(-100%);
  transition: transform .25s ease;
  padding-top: env(safe-area-inset-top);
  box-shadow: 4px 0 24px rgba(0, 0, 0, .25);
}
.drawer-open .drawer { transform: none; }
.drawer-overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .45);
  z-index: 40; opacity: 0; pointer-events: none; transition: opacity .25s;
}
.drawer-open .drawer-overlay { opacity: 1; pointer-events: auto; }
.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 14px 12px 16px; border-bottom: 1px solid rgba(255, 255, 255, .08);
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; min-width: 0; }
.brand:hover { text-decoration: none; }
.brand-icon { width: 40px; height: 40px; border-radius: 10px; flex: none; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text strong { font-size: 1.15rem; letter-spacing: .3px; }
.brand-text small { color: rgba(255, 255, 255, .6); font-size: .78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drawer-nav { flex: 1; overflow-y: auto; padding: 8px 10px 16px; overscroll-behavior: contain; }
.nav-section { font-size: .7rem; text-transform: uppercase; letter-spacing: 1.2px; color: rgba(255, 255, 255, .45); padding: 14px 10px 6px; }
.nav-link {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; margin: 2px 0; border-radius: 9px;
  color: rgba(255, 255, 255, .82) !important; font-size: .95rem;
}
.nav-link:hover { background: rgba(255, 255, 255, .07); text-decoration: none; color: #fff !important; }
.nav-link.active { background: var(--primary); color: #fff !important; box-shadow: 0 4px 12px rgba(0, 0, 0, .25); }
.nav-link i { width: 20px; text-align: center; opacity: .9; }
.nav-badge { margin-left: auto; background: var(--accent); color: #fff; font-style: normal; font-size: .72rem; font-weight: 700; padding: 1px 8px; border-radius: 20px; }
.drawer-foot { padding: 12px 18px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid rgba(255, 255, 255, .08); font-size: .8rem; }
.gw-status i { font-size: .6rem; vertical-align: middle; margin-right: 4px; }
.gw-status.on i { color: #7cdc5a; }
.gw-status.off i { color: #ff6b6b; }

/* ---------- Main area ---------- */
.main { min-width: 0; min-height: 100vh; display: flex; flex-direction: column; transition: margin-left .25s ease; }
.topbar {
  position: sticky; top: 0; z-index: 30;
  height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 12px 0;
  display: flex; align-items: center; gap: 8px;
  background: var(--primary); color: #fff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .15);
}
.topbar-title { font-size: 1.1rem; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; align-items: center; gap: 4px; }
.icon-btn {
  position: relative;
  width: 40px; height: 40px; border: 0; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; color: inherit; font-size: 1.1rem; cursor: pointer;
}
.topbar .icon-btn, .topbar a.icon-btn { color: #fff !important; }
.icon-btn:hover { background: rgba(255, 255, 255, .14); text-decoration: none; }
.icon-btn .dot { position: absolute; top: 8px; right: 8px; width: 9px; height: 9px; border-radius: 50%; background: var(--accent); border: 2px solid var(--primary); }
.user-chip { display: flex; align-items: center; gap: 8px; color: #fff !important; padding: 4px 6px; border-radius: 30px; }
.user-chip:hover { background: rgba(255, 255, 255, .14); text-decoration: none; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--side); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; }
.user-name { display: none; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.content { flex: 1; width: 100%; max-width: 1400px; margin: 0 auto; padding: 16px; }

/* Desktop & landscape tablet: persistent drawer */
@media (min-width: 1024px) {
  .drawer { transform: none; box-shadow: none; }
  .drawer-close { display: none; }
  .drawer-overlay { display: none; }
  .main { margin-left: var(--drawer-w); }
  .drawer-collapsed .drawer { transform: translateX(-100%); }
  .drawer-collapsed .main { margin-left: 0; }
  .content { padding: 24px; }
  .user-name { display: inline; }
}
@media (min-width: 600px) { .content { padding: 20px; } }

/* ---------- Cards & grid ---------- */
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px; margin-bottom: 16px; border: 1px solid var(--line);
  min-width: 0;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.card-head h2, .card-head h3 { margin: 0; }
.grid { display: grid; gap: 16px; }
.grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); }
.grid > *, .layout-main-side > * { min-width: 0; }
@media (min-width: 600px) {
  .grid-2 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 900px) {
  .grid-3 { grid-template-columns: repeat(3, 1fr); }
  .grid-4 { grid-template-columns: repeat(4, 1fr); }
}
.layout-main-side { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 1100px) { .layout-main-side { grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); } }

.stat { display: flex; align-items: center; gap: 14px; }
.stat-icon { width: 50px; height: 50px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 1.3rem; color: #fff; background: var(--primary); flex: none; }
.stat-icon.accent { background: var(--accent); }
.stat-icon.side { background: var(--side); }
.stat-icon.warn { background: var(--warn); }
.stat-icon.danger { background: var(--danger); }
.stat-value { font-size: 1.6rem; font-weight: 700; line-height: 1.1; }
.stat-label { color: var(--muted); font-size: .85rem; }

/* Quick actions */
.quick { display: grid; gap: 12px; grid-template-columns: repeat(2, 1fr); }
@media (min-width: 700px) { .quick { grid-template-columns: repeat(4, 1fr); } }
.quick a {
  display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center;
  padding: 18px 10px; border-radius: var(--radius); background: var(--side); color: #fff !important; font-weight: 600;
}
.quick a i { font-size: 1.5rem; color: var(--accent); }
.quick a:hover { text-decoration: none; filter: brightness(1.15); }

/* Bar chart */
.bars { display: flex; align-items: flex-end; gap: 8px; height: 170px; padding-top: 10px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 6px; min-width: 0; }
.bar { width: 100%; max-width: 44px; background: var(--primary); border-radius: 6px 6px 2px 2px; min-height: 2px; position: relative; }
.bar span { position: absolute; top: -20px; left: 50%; transform: translateX(-50%); font-size: .75rem; color: var(--muted); }
.bar-col small { color: var(--muted); font-size: .72rem; white-space: nowrap; }

/* Progress */
.progress { height: 10px; background: var(--line); border-radius: 10px; overflow: hidden; display: flex; }
.progress > div { height: 100%; }
.progress .p-ok { background: var(--ok); }
.progress .p-fail { background: var(--danger); }
.progress .p-pending { background: var(--warn); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: 9px; border: 1px solid transparent;
  background: var(--primary); color: #fff !important; font-size: .95rem; font-weight: 600;
  cursor: pointer; line-height: 1.2; white-space: nowrap; font-family: inherit;
}
.btn:hover { background: var(--primary-d); text-decoration: none; }
.btn-accent { background: var(--accent); }
.btn-accent:hover { background: var(--accent); filter: brightness(.9); }
.btn-dark { background: var(--side); }
.btn-dark:hover { background: var(--side); filter: brightness(1.3); }
.btn-outline { background: transparent; color: var(--text) !important; border-color: var(--line); }
.btn-outline:hover { background: color-mix(in srgb, var(--primary) 10%, transparent); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #b71c1c; }
.btn-sm { padding: 6px 11px; font-size: .84rem; border-radius: 7px; }
.btn-block { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* ---------- Forms ---------- */
.form-group { margin-bottom: 14px; }
label, .label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: 5px; }
.input, select, textarea, input[type=text], input[type=password], input[type=number], input[type=datetime-local], input[type=search], input[type=tel], input[type=file] {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px;
  background: var(--input); color: var(--text); font: inherit; font-size: 16px; /* 16px stops iOS zoom */
}
textarea { min-height: 120px; resize: vertical; }
.input:focus, select:focus, textarea:focus, input:focus { outline: 2px solid color-mix(in srgb, var(--primary) 45%, transparent); border-color: var(--primary); }
.form-row { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 600px) { .form-row { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); } }
.help-text { color: var(--muted); font-size: .8rem; margin-top: 4px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; margin: 0; }
.check input { width: 18px; height: 18px; accent-color: var(--primary); flex: none; }
.check-list { display: grid; gap: 8px; grid-template-columns: 1fr; max-height: 260px; overflow-y: auto; padding: 10px; border: 1px solid var(--line); border-radius: 9px; background: var(--input); }
@media (min-width: 600px) { .check-list { grid-template-columns: repeat(2, 1fr); } }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.toolbar .input, .toolbar select { width: auto; flex: 1 1 160px; }
.counter { display: flex; justify-content: space-between; font-size: .8rem; color: var(--muted); margin-top: 4px; gap: 8px; flex-wrap: wrap; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip { border: 1px dashed var(--primary); color: var(--primary); background: transparent; border-radius: 20px; padding: 3px 10px; font-size: .8rem; cursor: pointer; font-family: inherit; }
[data-theme="dark"] .chip { color: var(--text); }
.chip:hover { background: var(--primary); color: #fff; }

/* Tabs */
.tabs { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 16px; padding-bottom: 2px; }
.tabs a { flex: none; padding: 9px 16px; border-radius: 30px; background: var(--card); border: 1px solid var(--line); color: var(--text) !important; font-weight: 600; font-size: .9rem; }
.tabs a.active { background: var(--side); color: #fff !important; border-color: var(--side); }
.tabs a:hover { text-decoration: none; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -4px; }
table.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { padding: 10px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.table th { font-size: .76rem; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); white-space: nowrap; }
.table tr:hover td { background: color-mix(in srgb, var(--primary) 4%, transparent); }
.table .msg-cell { max-width: 380px; white-space: pre-line; word-break: break-word; }
/* Phones: tables become stacked cards */
@media (max-width: 700px) {
  .table.stack thead { display: none; }
  .table.stack, .table.stack tbody, .table.stack tr, .table.stack td { display: block; width: 100%; }
  .table.stack tr { border: 1px solid var(--line); border-radius: 10px; margin-bottom: 10px; padding: 6px 10px; background: var(--card); }
  .table.stack td { border: 0; padding: 5px 0; display: flex; gap: 10px; justify-content: space-between; text-align: right; }
  .table.stack td::before { content: attr(data-label); font-weight: 600; color: var(--muted); font-size: .8rem; text-align: left; flex: none; }
  .table.stack td.msg-cell { display: block; text-align: left; max-width: none; }
  .table.stack td.msg-cell::before { display: block; }
}

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 20px; font-size: .76rem; font-weight: 600; white-space: nowrap; background: var(--line); color: var(--text); }
.badge-queued { background: #fff3e0; color: #b45f00; }
.badge-sending { background: #e3f2fd; color: #1565c0; }
.badge-sent { background: #e8f5e9; color: #2e7d32; }
.badge-delivered { background: #2e7d32; color: #fff; }
.badge-failed { background: #ffebee; color: #c62828; }
.badge-cancelled { background: #eceff1; color: #546e7a; }
.badge-on { background: #e8f5e9; color: #2e7d32; }
.badge-off { background: #ffebee; color: #c62828; }
.badge-type { background: var(--side); color: #fff; }
[data-theme="dark"] .badge-queued, [data-theme="dark"] .badge-sending, [data-theme="dark"] .badge-sent,
[data-theme="dark"] .badge-failed, [data-theme="dark"] .badge-cancelled, [data-theme="dark"] .badge-on, [data-theme="dark"] .badge-off { filter: brightness(.85) saturate(1.2); }

/* Alerts */
.alert { display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; border-radius: 10px; margin-bottom: 14px; border-left: 4px solid; background: var(--card); box-shadow: var(--shadow); }
.alert span { flex: 1; }
.alert-success { border-color: var(--ok); } .alert-success i { color: var(--ok); }
.alert-error { border-color: var(--danger); } .alert-error i { color: var(--danger); }
.alert-info { border-color: var(--primary); } .alert-info i { color: var(--primary); }
.alert-warn { border-color: var(--warn); } .alert-warn > i { color: var(--warn); }
.alert-close { background: none; border: 0; font-size: 1.3rem; line-height: 1; cursor: pointer; color: var(--muted); }

/* Templates */
.tpl-card { display: flex; flex-direction: column; }
.tpl-card .tpl-body { white-space: pre-line; color: var(--muted); font-size: .88rem; flex: 1; margin: 8px 0 14px; max-height: 150px; overflow: hidden; position: relative; }
.tpl-cat { display: inline-block; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; color: #fff; background: var(--primary); padding: 2px 9px; border-radius: 20px; }

/* SMS phone preview */
.phone-preview { background: var(--side); border-radius: 22px; padding: 16px 12px; min-height: 160px; }
.phone-preview .bubble { background: #fff; color: #1c2733; border-radius: 16px 16px 16px 4px; padding: 10px 13px; white-space: pre-wrap; word-break: break-word; font-size: .92rem; max-width: 92%; }
.phone-preview .bubble:empty::before { content: "Your message preview appears here…"; color: #8a97a5; }
.phone-preview .from { color: rgba(255, 255, 255, .6); font-size: .75rem; margin-bottom: 6px; }

/* Theme swatches */
.swatches { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
.swatch { position: relative; cursor: pointer; border: 2px solid var(--line); border-radius: 12px; overflow: hidden; display: block; margin: 0; font-weight: 600; }
.swatch input { position: absolute; opacity: 0; }
.swatch .sw-colors { display: flex; height: 46px; }
.swatch .sw-colors span { flex: 1; }
.swatch .sw-name { display: block; padding: 6px 8px; font-size: .82rem; background: var(--card); }
.swatch:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 40%, transparent); }

/* FAQ / manual */
details.faq { border: 1px solid var(--line); border-radius: 10px; margin-bottom: 10px; background: var(--card); }
details.faq summary { cursor: pointer; padding: 13px 16px; font-weight: 600; list-style: none; display: flex; justify-content: space-between; gap: 10px; }
details.faq summary::-webkit-details-marker { display: none; }
details.faq summary::after { content: "+"; font-size: 1.3rem; line-height: 1; color: var(--primary); }
details.faq[open] summary::after { content: "−"; }
details.faq .faq-body { padding: 0 16px 14px; color: var(--muted); }
.toc { columns: 1; padding-left: 1.2rem; }
@media (min-width: 700px) { .toc { columns: 2; } }
.manual h2 { margin-top: 1.6rem; padding-top: .6rem; border-top: 1px solid var(--line); scroll-margin-top: 80px; }
.manual h2:first-of-type { border-top: 0; margin-top: 0; }
.manual li { margin-bottom: .35rem; }
.steps { counter-reset: s; list-style: none; padding: 0; }
.steps li { counter-increment: s; position: relative; padding: 0 0 14px 46px; }
.steps li::before { content: counter(s); position: absolute; left: 0; top: 0; width: 32px; height: 32px; border-radius: 50%; background: var(--primary); color: #fff; font-weight: 700; display: flex; align-items: center; justify-content: center; }

/* Empty state */
.empty { text-align: center; padding: 34px 10px; color: var(--muted); }
.empty i { font-size: 2.4rem; color: var(--primary); opacity: .5; margin-bottom: 10px; display: block; }

/* Pager */
.pager { display: flex; justify-content: center; align-items: center; gap: 12px; margin-top: 14px; flex-wrap: wrap; }
.pager a, .pager span { padding: 6px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); font-size: .88rem; }
.pager .disabled { opacity: .45; }
.pager .pager-info { border: 0; background: none; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .5); z-index: 60; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-box { background: var(--card); border-radius: var(--radius); padding: 20px; width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto; }

/* Footer */
.site-footer { text-align: center; padding: 22px 16px calc(22px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--card); font-size: .88rem; }
.site-footer p { margin: 4px 0; }
.footer-logo { display: inline-block; background: #fff; padding: 6px 12px; border-radius: 10px; margin-bottom: 6px; }
.footer-logo img { height: 36px; display: block; }

/* ---------- Auth pages ---------- */
.auth-body { display: flex; align-items: center; justify-content: center; padding: 20px; background: radial-gradient(circle at 20% 10%, var(--primary) 0, var(--side) 55%); min-height: 100vh; flex-direction: column; }
.auth-card { width: 100%; max-width: 410px; background: var(--card); border-radius: 18px; padding: 28px 24px; box-shadow: 0 20px 50px rgba(0, 0, 0, .35); }
.auth-card .logo { text-align: center; margin-bottom: 18px; }
.auth-card .logo img { width: 74px; height: 74px; border-radius: 18px; }
.auth-card .logo h1 { margin: 10px 0 2px; font-size: 1.6rem; }
.auth-foot { color: rgba(255, 255, 255, .8); text-align: center; margin-top: 18px; font-size: .85rem; }
.auth-foot a { color: #fff !important; font-weight: 600; }
.auth-foot img { height: 34px; background: #fff; padding: 4px 10px; border-radius: 8px; margin-bottom: 6px; }
@media (orientation: landscape) and (max-height: 520px) {
  .auth-body { justify-content: flex-start; }
  .auth-card .logo img { width: 48px; height: 48px; }
}

@media print {
  .drawer, .topbar, .site-footer, .btn, .toolbar { display: none !important; }
  .main { margin: 0 !important; }
}

/* Console log (System Updates) */
.console { background: #0b1220; color: #d6e2f0; font-family: Consolas, "Cascadia Mono", Menlo, monospace; font-size: .82rem; line-height: 1.55; padding: 12px 14px; border-radius: 9px; white-space: pre-wrap; word-break: break-word; margin: 0 0 4px; max-height: 360px; overflow: auto; }
