/**
 * AI SMS Platform — dashboard stylesheet.
 *
 * Hand-written and served directly, with no build step: `composer install` and
 * `php artisan migrate` are enough to run the application. That keeps cPanel
 * and shared-hosting deployments (the likely first home for this product)
 * simple, and there is no npm toolchain to keep alive.
 *
 * Visual direction: modern SaaS, light by default, minimal, no gradients and no
 * decorative animation. Dark mode follows the operating system.
 */

/* ============================================================ Design tokens */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #fbfbfc;
  --border: #e3e6ea;
  --border-strong: #cdd3da;

  --text: #14181f;
  --text-muted: #5c6672;
  --text-subtle: #8b95a1;

  --primary: #1f6feb;
  --primary-hover: #1a5fd0;
  --primary-soft: #eaf1fe;

  --success: #16794a;
  --success-soft: #e6f4ed;
  --warning: #96601a;
  --warning-soft: #fdf3e3;
  --danger: #b3261e;
  --danger-soft: #fdecea;
  --info: #1f5f8b;
  --info-soft: #e9f2f8;

  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 1px 3px rgb(16 24 40 / 4%);
  --shadow-lg: 0 8px 24px rgb(16 24 40 / 10%);

  --sidebar-width: 232px;
  --topbar-height: 56px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    "Noto Sans Bengali", "SolaimanLipi", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1117;
    --surface: #161b22;
    --surface-2: #1c2128;
    --border: #2a313a;
    --border-strong: #3a424d;

    --text: #e6edf3;
    --text-muted: #9aa5b1;
    --text-subtle: #7d8590;

    --primary: #4c8dfa;
    --primary-hover: #6ba1fb;
    --primary-soft: #16273f;

    --success: #57d38c;
    --success-soft: #10261a;
    --warning: #e3ac5a;
    --warning-soft: #2a1f0d;
    --danger: #f07a72;
    --danger-soft: #2d1513;
    --info: #6cb6e8;
    --info-soft: #10222e;

    --shadow: 0 1px 2px rgb(0 0 0 / 30%);
    --shadow-lg: 0 8px 24px rgb(0 0 0 / 40%);
  }
}

/* Dark tokens repeated for the explicit toggle, so a chosen theme wins in
   both directions regardless of the system setting. */
:root[data-theme="dark"] {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #1c2128;
  --border: #2a313a;
  --border-strong: #3a424d;
  --text: #e6edf3;
  --text-muted: #9aa5b1;
  --text-subtle: #7d8590;
  --primary: #4c8dfa;
  --primary-hover: #6ba1fb;
  --primary-soft: #16273f;
  --success: #57d38c;
  --success-soft: #10261a;
  --warning: #e3ac5a;
  --warning-soft: #2a1f0d;
  --danger: #f07a72;
  --danger-soft: #2d1513;
  --info: #6cb6e8;
  --info-soft: #10222e;
}

/* ================================================================== Reset */

*,
*::before,
*::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0 0 .5rem; font-weight: 600; line-height: 1.3; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

img { max-width: 100%; height: auto; }

code, pre, .mono { font-family: var(--mono); font-size: .85em; }

/* ================================================================ Layout */

.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-width);
  flex: 0 0 var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: 0 1rem;
  height: var(--topbar-height);
  border-bottom: 1px solid var(--border);
  font-weight: 650;
  color: var(--text);
  flex: 0 0 auto;
}
.sidebar__brand:hover { text-decoration: none; }

.sidebar__mark {
  width: 26px; height: 26px;
  border-radius: 6px;
  background: var(--primary);
  color: #fff;
  display: grid; place-items: center;
  font-size: .75rem; font-weight: 700;
}

.sidebar__nav { padding: .75rem .5rem; flex: 1 1 auto; }

.sidebar__section {
  padding: .75rem .75rem .25rem;
  font-size: .68rem;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-subtle);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .5rem .75rem;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 1px;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-item.is-active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav-item__icon { width: 16px; text-align: center; flex: 0 0 16px; opacity: .9; }
.nav-item__badge {
  margin-left: auto;
  background: var(--danger);
  color: #fff;
  border-radius: 10px;
  padding: 0 .4rem;
  font-size: .7rem;
  font-weight: 600;
  min-width: 18px;
  text-align: center;
}

.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: var(--topbar-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: 0 1rem;
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar__search { flex: 1 1 auto; max-width: 420px; }
.topbar__spacer { flex: 1 1 auto; }

.content { padding: 1.25rem; flex: 1 1 auto; }
.content--flush { padding: 0; }

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}
.page-header__title { margin: 0; }
.page-header__sub { color: var(--text-muted); margin: .15rem 0 0; font-size: .875rem; }
.page-header__actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* ================================================================= Cards */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
.card__header {
  padding: .875rem 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
}
.card__title { margin: 0; font-size: .95rem; font-weight: 600; }
.card__body { padding: 1rem; }
.card__footer { padding: .75rem 1rem; border-top: 1px solid var(--border); background: var(--surface-2); }

.grid { display: grid; gap: 1rem; }
.grid--stats { grid-template-columns: repeat(auto-fit, minmax(168px, 1fr)); }
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid--3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid--sidebar { grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr); }

@media (max-width: 900px) {
  .grid--sidebar { grid-template-columns: 1fr; }
}

/* Deliberately restrained: a number and a label, not a giant tile. */
.stat { padding: .875rem 1rem; }
.stat__label {
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-subtle);
  font-weight: 600;
  margin-bottom: .25rem;
}
.stat__value { font-size: 1.5rem; font-weight: 650; line-height: 1.1; }
.stat__meta { font-size: .78rem; color: var(--text-muted); margin-top: .2rem; }

/* ================================================================ Tables */

.table-wrap { overflow-x: auto; }

table.table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}
.table th {
  text-align: left;
  padding: .6rem .75rem;
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-subtle);
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td {
  padding: .65rem .75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table--compact td, .table--compact th { padding: .45rem .6rem; }

/* ================================================================ Badges */

.badge {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .12rem .45rem;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
}
.badge--neutral { background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border); }
.badge--primary { background: var(--primary-soft); color: var(--primary); }
.badge--success { background: var(--success-soft); color: var(--success); }
.badge--warning { background: var(--warning-soft); color: var(--warning); }
.badge--danger { background: var(--danger-soft); color: var(--danger); }
.badge--info { background: var(--info-soft); color: var(--info); }

/* ================================================================ Forms */

.field { margin-bottom: 1rem; }
.field:last-child { margin-bottom: 0; }

.label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  margin-bottom: .3rem;
  color: var(--text);
}
.help { font-size: .78rem; color: var(--text-muted); margin-top: .3rem; }
.error { font-size: .78rem; color: var(--danger); margin-top: .3rem; }

.input, .select, .textarea {
  width: 100%;
  padding: .5rem .65rem;
  font: inherit;
  font-size: .875rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  transition: border-color .12s, box-shadow .12s;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.input[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--danger); }
.textarea { min-height: 110px; resize: vertical; line-height: 1.55; }
.input--sm { padding: .35rem .5rem; font-size: .82rem; }

.checkbox, .radio {
  display: flex;
  align-items: flex-start;
  gap: .5rem;
  font-size: .875rem;
  cursor: pointer;
  margin-bottom: .4rem;
}
.checkbox input, .radio input { margin-top: .2rem; flex: 0 0 auto; }

.form-row { display: flex; gap: .75rem; flex-wrap: wrap; align-items: flex-end; }
.form-row > * { flex: 1 1 180px; }
.form-row > .form-row__fixed { flex: 0 0 auto; }

/* =============================================================== Buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .5rem .85rem;
  font: inherit;
  font-size: .85rem;
  font-weight: 600;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  background: var(--surface);
  color: var(--text);
  white-space: nowrap;
  transition: background .12s, border-color .12s, opacity .12s;
}
.btn:hover { text-decoration: none; }
.btn:disabled, .btn.is-loading { opacity: .6; cursor: not-allowed; }

.btn--primary { background: var(--primary); color: #fff; }
.btn--primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn--secondary { background: var(--surface); border-color: var(--border-strong); color: var(--text); }
.btn--secondary:hover:not(:disabled) { background: var(--surface-2); }
.btn--danger { background: var(--danger); color: #fff; }
.btn--ghost { background: transparent; color: var(--text-muted); }
.btn--ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.btn--sm { padding: .3rem .6rem; font-size: .78rem; }
.btn--block { width: 100%; }

.btn-group { display: flex; gap: .4rem; flex-wrap: wrap; }

/* ================================================================ Alerts */

.alert {
  padding: .7rem .9rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: .875rem;
  border: 1px solid transparent;
}
.alert--success { background: var(--success-soft); color: var(--success); border-color: currentColor; }
.alert--error { background: var(--danger-soft); color: var(--danger); border-color: currentColor; }
.alert--warning { background: var(--warning-soft); color: var(--warning); border-color: currentColor; }
.alert--info { background: var(--info-soft); color: var(--info); border-color: currentColor; }
.alert ul { margin: .4rem 0 0; padding-left: 1.1rem; }

/* ============================================================== Progress */

.progress {
  height: 6px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.progress__bar { height: 100%; background: var(--primary); border-radius: 999px; transition: width .3s ease; }
.progress__bar--success { background: var(--success); }
.progress__bar--danger { background: var(--danger); }

/* ================================================================= Chart */

/* A pure-CSS column chart: no charting library, no external request. */
.chart { display: flex; align-items: flex-end; gap: 3px; height: 180px; padding-top: .5rem; }
.chart__col { flex: 1 1 0; display: flex; flex-direction: column; justify-content: flex-end; gap: 1px; min-width: 0; }
.chart__seg { width: 100%; border-radius: 2px 2px 0 0; min-height: 1px; }
.chart__seg--sent { background: var(--primary); }
.chart__seg--delivered { background: var(--success); }
.chart__seg--failed { background: var(--danger); }
.chart__seg--inbound { background: var(--info); }
.chart__label {
  font-size: .62rem;
  color: var(--text-subtle);
  text-align: center;
  margin-top: .3rem;
  white-space: nowrap;
  overflow: hidden;
}
.chart-legend { display: flex; gap: 1rem; flex-wrap: wrap; font-size: .78rem; color: var(--text-muted); margin-top: .75rem; }
.chart-legend__dot { width: 9px; height: 9px; border-radius: 2px; display: inline-block; margin-right: .3rem; }

/* ================================================================= Inbox */

.inbox {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 280px;
  height: calc(100vh - var(--topbar-height));
}
.inbox__col { display: flex; flex-direction: column; min-width: 0; border-right: 1px solid var(--border); background: var(--surface); }
.inbox__col:last-child { border-right: 0; }
.inbox__header { padding: .75rem; border-bottom: 1px solid var(--border); flex: 0 0 auto; }
.inbox__scroll { flex: 1 1 auto; overflow-y: auto; }
.inbox__footer { border-top: 1px solid var(--border); padding: .75rem; flex: 0 0 auto; background: var(--surface); }

.conv {
  display: block;
  padding: .7rem .75rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.conv:hover { background: var(--surface-2); text-decoration: none; }
.conv.is-active { background: var(--primary-soft); }
.conv__top { display: flex; justify-content: space-between; gap: .5rem; align-items: baseline; }
.conv__name { font-weight: 600; font-size: .875rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv__time { font-size: .7rem; color: var(--text-subtle); flex: 0 0 auto; }
.conv__preview {
  font-size: .8rem;
  color: var(--text-muted);
  margin-top: .15rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.conv.is-unread .conv__name { font-weight: 700; }
.conv.is-unread .conv__preview { color: var(--text); font-weight: 500; }

.thread { padding: 1rem; display: flex; flex-direction: column; gap: .6rem; }

.bubble { max-width: min(78%, 520px); padding: .55rem .75rem; border-radius: 12px; font-size: .875rem; word-wrap: break-word; }
.bubble--in { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--border); border-bottom-left-radius: 3px; }
.bubble--out { align-self: flex-end; background: var(--primary); color: #fff; border-bottom-right-radius: 3px; }
.bubble--ai { align-self: flex-end; background: var(--info-soft); color: var(--text); border: 1px dashed var(--info); }
.bubble__meta { font-size: .68rem; opacity: .75; margin-top: .25rem; display: flex; gap: .4rem; align-items: center; }
.bubble--out .bubble__meta { color: rgb(255 255 255 / 85%); }

/* On a phone the three columns become one, driven by a body class the layout
   sets from the current route. */
@media (max-width: 1100px) {
  .inbox { grid-template-columns: 260px minmax(0, 1fr); }
  .inbox__col--details { display: none; }
}
@media (max-width: 760px) {
  .inbox { grid-template-columns: 1fr; }
  .inbox__col--list { display: none; }
  .inbox--list-only .inbox__col--list { display: flex; }
  .inbox--list-only .inbox__col--thread { display: none; }
}

/* ================================================================ Wizard */

.wizard-steps {
  display: flex;
  gap: .5rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}
.wizard-step {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .5rem .8rem;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: .82rem;
  color: var(--text-muted);
  flex: 1 1 160px;
}
.wizard-step.is-current { border-color: var(--primary); color: var(--primary); font-weight: 600; background: var(--primary-soft); }
.wizard-step.is-done { color: var(--success); border-color: var(--success); }
.wizard-step__num {
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--border);
  color: var(--text-muted);
  display: grid; place-items: center;
  font-size: .7rem; font-weight: 700;
  flex: 0 0 auto;
}
.wizard-step.is-current .wizard-step__num { background: var(--primary); color: #fff; }
.wizard-step.is-done .wizard-step__num { background: var(--success); color: #fff; }

.composer-meta {
  display: flex;
  gap: 1rem;
  font-size: .78rem;
  color: var(--text-muted);
  margin-top: .4rem;
  flex-wrap: wrap;
  font-variant-numeric: tabular-nums;
}
.composer-meta strong { color: var(--text); font-weight: 600; }
.composer-meta.is-over strong { color: var(--danger); }

.sms-preview {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .75rem;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-size: .875rem;
  line-height: 1.6;
}

/* ================================================================= Misc */

.muted { color: var(--text-muted); }
.subtle { color: var(--text-subtle); }
.small { font-size: .8rem; }
.tabular { font-variant-numeric: tabular-nums; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nowrap { white-space: nowrap; }

.stack > * + * { margin-top: .75rem; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.row--between { justify-content: space-between; }
.row--end { justify-content: flex-end; }

.mt-0 { margin-top: 0; }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: .5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }

.empty {
  padding: 2.5rem 1rem;
  text-align: center;
  color: var(--text-muted);
}
.empty__title { font-weight: 600; color: var(--text); margin-bottom: .25rem; }

.pagination { display: flex; gap: .25rem; flex-wrap: wrap; align-items: center; padding: .75rem 0; font-size: .82rem; }
.pagination a, .pagination span {
  padding: .3rem .6rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  color: var(--text-muted);
  background: var(--surface);
}
.pagination .is-active span { background: var(--primary); border-color: var(--primary); color: #fff; }
.pagination .disabled span { opacity: .45; }

.dropdown { position: relative; }
.dropdown__menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 240px;
  max-width: 340px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 40;
  overflow: hidden;
  display: none;
}
.dropdown.is-open .dropdown__menu { display: block; }
.dropdown__item {
  display: block;
  padding: .55rem .75rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-size: .82rem;
}
.dropdown__item:last-child { border-bottom: 0; }
.dropdown__item:hover { background: var(--surface-2); text-decoration: none; }
.dropdown__item.is-unread { background: var(--primary-soft); }

.avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  display: grid; place-items: center;
  font-weight: 650;
  font-size: .78rem;
  flex: 0 0 auto;
}

.kbd {
  font-family: var(--mono);
  font-size: .72rem;
  padding: .1rem .3rem;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--surface-2);
}

.divider { height: 1px; background: var(--border); margin: 1rem 0; border: 0; }

.sidebar-toggle { display: none; }

/* ======================================================= Small viewports */

@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    z-index: 60;
    transform: translateX(-100%);
    transition: transform .18s ease;
    box-shadow: var(--shadow-lg);
  }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open::after {
    content: "";
    position: fixed;
    inset: 0;
    background: rgb(0 0 0 / 35%);
    z-index: 50;
  }
  .sidebar-toggle { display: inline-flex; }
  .content { padding: 1rem .75rem; }
  .topbar__search { max-width: none; }
}

@media print {
  .sidebar, .topbar, .page-header__actions, .btn { display: none !important; }
  .content { padding: 0; }
  .card { border-color: #ccc; box-shadow: none; }
}
