:root {
  --navy: #1f3a5f; --navy-2: #2c4f7c; --bg: #f4f6f9; --card: #fff; --line: #e3e7ee;
  --text: #1d2433; --muted: #6b7486; --green: #1e9e5a; --blue: #2f6fdb; --amber: #c98a00;
  --red: #d33a3a; --grey: #a3abba; --radius: 10px;
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 -apple-system, "Segoe UI", Roboto, Arial, sans-serif; color: var(--text); background: var(--bg); }
a { color: var(--blue); text-decoration: none; }
h1 { font-size: 22px; margin: 0 0 4px; }
h3 { font-size: 15px; margin: 0 0 12px; }
small { font-size: 12px; }
.muted { color: var(--muted); }
.text-danger { color: var(--red); }
.nowrap { white-space: nowrap; }
.center { text-align: center; }
.inline { display: inline; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 24px; background: var(--brand, var(--navy)); color: #fff; flex-wrap: wrap; }
.topbar nav { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.topbar nav a, .topbar .linklike { color: #dbe5f3; }
.topbar nav a:hover, .topbar .linklike:hover { color: #fff; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff !important; font-weight: 700; font-size: 16px; }
.brand small { font-weight: 400; color: #b8c7dc; margin-left: 4px; }
.logo { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; background: #fff; color: var(--navy); font-weight: 800; }
.linklike { background: none; border: 0; padding: 0; font: inherit; cursor: pointer; }
.banner { background: #fff6dd; color: #6b4e00; padding: 8px 24px; border-bottom: 1px solid #f0e0b0; font-size: 13px; }

.container { max-width: 1240px; margin: 0 auto; padding: 24px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.card.narrow { max-width: 460px; }
.empty { text-align: center; padding: 48px; }
.two-col { display: grid; grid-template-columns: 1fr 1.6fr; gap: 16px; align-items: start; }
.two-col.wide-left { grid-template-columns: 2.2fr 1fr; }
@media (max-width: 900px) { .two-col, .two-col.wide-left { grid-template-columns: 1fr; } }

.btn { display: inline-block; padding: 7px 14px; border: 1px solid var(--line); border-radius: 7px; background: #fff; color: var(--text); font: inherit; cursor: pointer; line-height: 1.3; }
.btn:hover { border-color: #c5ccd8; }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-primary { background: var(--blue); border-color: var(--blue); color: #fff !important; }
.btn-primary:hover { background: #255fc4; }
.btn-danger { color: var(--red); border-color: #f0c4c4; }
.btn-block { width: 100%; padding: 10px; margin-top: 6px; }

label { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: 13px; margin-bottom: 12px; }
input, select, textarea { font: inherit; font-weight: 400; padding: 8px 10px; border: 1px solid #cfd5df; border-radius: 7px; background: #fff; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid #bcd2fb; border-color: var(--blue); }
.prefix { display: flex; }
.prefix span { padding: 8px 10px; border: 1px solid #cfd5df; border-right: 0; border-radius: 7px 0 0 7px; background: #f1f3f7; font-weight: 400; }
.prefix input { border-radius: 0 7px 7px 0; }
.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); column-gap: 16px; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid h3 { margin-top: 6px; color: var(--navy); }
@media (max-width: 800px) { .form-grid { grid-template-columns: 1fr; } }
.form-foot { display: flex; justify-content: space-between; align-items: center; gap: 16px; border-top: 1px solid var(--line); padding-top: 14px; flex-wrap: wrap; }
.form-foot p { margin: 0; max-width: 640px; }

.filters { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.filters input, .filters select { width: auto; padding: 5px 8px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; background: #fff; }
.seg a { padding: 5px 12px; color: var(--muted); }
.seg a.active { background: var(--navy); color: #fff; }

.table-wrap { padding: 0; overflow-x: auto; }
.grid { width: 100%; border-collapse: collapse; }
.grid th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--line); background: #fafbfc; }
.grid td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.grid tr:last-child td { border-bottom: 0; }
.grid.compact td, .grid.compact th { padding: 7px 8px; }
.row-cancelled td { opacity: .5; }

.dot { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; font-size: 10px; font-weight: 700; color: #fff; margin: 0 2px; cursor: default; }
.dot-pending, .dot-sending { background: #fff; color: var(--muted); border: 1.5px dashed var(--grey); }
.dot-sent { background: var(--grey); }
.dot-delivered { background: var(--blue); }
.dot-read { background: var(--green); }
.dot-failed, .dot-missed { background: var(--red); }
.dot-none { background: none; color: var(--grey); }
.legend { margin-top: 10px; font-size: 12px; }
.legend .dot { width: 16px; height: 16px; font-size: 9px; margin-left: 10px; }

.pill { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; background: #eef1f6; color: var(--muted); text-transform: capitalize; }
.pill-sent { background: #eceff4; color: #4d566a; }
.pill-delivered { background: #e5efff; color: var(--blue); }
.pill-read { background: #e2f5ea; color: var(--green); }
.pill-failed, .pill-missed { background: #fde8e8; color: var(--red); }
.pill-pending, .pill-sending { background: #fff6dd; color: var(--amber); }
.pill-muted, .pill-cancelled { background: #eef0f3; color: #8a93a3; }

.kv { display: grid; grid-template-columns: 110px 1fr; gap: 8px 12px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; border: 1px solid; }
.flash-info { background: #eaf2ff; border-color: #c8dbfb; color: #1c4a9a; }
.flash-warning { background: #fff6dd; border-color: #f0e0b0; color: #6b4e00; }
.flash-error { background: #fde8e8; border-color: #f4c7c7; color: #9b1f1f; }

.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: linear-gradient(160deg, #eef3fb 0%, #f7f9fc 60%); }
.auth-card { width: 100%; max-width: 380px; }
.auth-brand { display: flex; gap: 12px; align-items: center; margin-bottom: 20px; }
.auth-brand .logo { background: var(--navy); color: #fff; width: 40px; height: 40px; font-size: 18px; }

.inline-details { display: inline-block; position: relative; }
.inline-details summary { list-style: none; }
.inline-details summary::-webkit-details-marker { display: none; }
.mini-form { position: absolute; right: 0; z-index: 5; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 10px; display: flex; flex-direction: column; gap: 6px; width: 220px; box-shadow: 0 6px 18px rgba(0,0,0,.08); }

/* ---- v2: multi-company product ---- */
.topbar nav a, .topbar .linklike { color: rgba(255,255,255,.82); }
.logo-chip { display: inline-grid; place-items: center; height: 34px; padding: 3px 6px; background: #fff; border-radius: 8px; }
.logo-chip img { max-height: 28px; max-width: 120px; display: block; }
.banner-support { background: #e8f0ff; color: #1c3f86; border-bottom-color: #c9d9fb; display: flex; align-items: center; gap: 12px; }
.banner-danger { background: #fde8e8; color: #8d1c1c; border-bottom-color: #f4c7c7; }
.footer { text-align: center; color: var(--muted); font-size: 12px; padding: 18px 0 28px; }
.footer a { color: var(--muted); font-weight: 600; }

.auth-wrap { width: 100%; max-width: 400px; }
.auth-card { max-width: none; }
.auth-brand { justify-content: center; }
.vendor-logo { max-width: 200px; max-height: 120px; }
.org-logo { max-height: 48px; max-width: 160px; }
.auth-title { text-align: center; margin: 4px 0 2px; font-size: 22px; color: #0b2a6f; }
.auth-sub { text-align: center; margin: 0 0 18px; }
.powered { text-align: center; color: var(--muted); font-size: 12px; margin-top: 14px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabs a { padding: 9px 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; display: inline-flex; gap: 6px; align-items: center; }
.tabs a.active { color: var(--text); border-bottom-color: var(--blue); font-weight: 600; }
.tabs .pill { font-size: 10px; padding: 1px 6px; }

.form-grid.two { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 800px) { .form-grid.two { grid-template-columns: 1fr; } }
.two-col.even { grid-template-columns: 1.4fr 1fr; margin-bottom: 16px; }
.narrow-wide { max-width: 640px; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; }
label.check input { width: auto; }
.color-row { display: flex; align-items: center; gap: 10px; }
.color-row input[type=color] { width: 56px; height: 36px; padding: 2px; }
.logo-preview { display: flex; align-items: center; gap: 12px; margin-top: 6px; }
.logo-preview img { max-height: 40px; max-width: 160px; border: 1px solid var(--line); border-radius: 6px; padding: 4px; background: #fff; }
.logo-preview label { margin: 0; }
code { background: #f1f3f7; padding: 1px 6px; border-radius: 4px; font-size: 12.5px; }
.small-note { font-size: 12px; margin-top: 10px; }
details summary { cursor: pointer; margin: 6px 0 10px; }
.add-admin { margin-top: 12px; }

.tpl { border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin-bottom: 12px; }
.tpl-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.tpl pre { white-space: pre-wrap; background: #f7f8fa; padding: 10px; border-radius: 6px; margin: 0 0 6px; font: 13px/1.5 ui-monospace, Consolas, monospace; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; color: var(--muted); font-size: 12.5px; }
.stat span { display: block; font-size: 22px; font-weight: 700; color: var(--text); margin-bottom: 2px; }
.card + .card, .two-col + .card { margin-top: 16px; }
.two-col > .card { margin-top: 0; }
.grid th.center { text-align: center; }

/* ---- reports ---- */
.report-form { margin-bottom: 16px; }
.report-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 0 14px; align-items: start; }
.multi { border: 1px solid #cfd5df; border-radius: 7px; padding: 0 10px; margin-bottom: 12px; background: #fff; position: relative; }
.multi summary { margin: 0; padding: 8px 0; font-size: 13px; }
.multi[open] summary { border-bottom: 1px solid var(--line); }
.multi-list { max-height: 220px; overflow: auto; padding: 8px 0; }
.multi-list label.check { margin-bottom: 6px; font-size: 13px; }
.report-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; border-top: 1px solid var(--line); padding-top: 14px; }
.report-actions .spacer { flex: 1; }
.report-head { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.row-total td { font-weight: 700; background: #f6f8fb; }
.logo-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.logo-row input[type=file] { width: auto; flex: 1; }
.logo-thumb { max-height: 40px; max-width: 160px; border: 1px solid var(--line); border-radius: 6px; padding: 4px; background: #fff; }
h3.mt { margin-top: 6px; }
