/* =====================================================================
   Star Causelist — shared stylesheet (admin + user portal)
   WhatsApp-inspired palette. Light / Dark / System via [data-theme].
   ===================================================================== */
:root {
  --brand: #075e54; --brand-2: #128c7e; --accent: #25d366; --accent-ink: #053d36;
  --bg: #f0f2f5; --surface: #ffffff; --surface-2: #f7f8fa; --chat-bg: #efeae2;
  --text: #111b21; --muted: #667781; --border: #e2e6ea;
  --bubble: #ffffff; --bubble-mine: #d9fdd3; --bubble-hl: #e7fce3;
  --danger: #d93025; --warn: #e8a10c; --ok: #1a9e5c; --info: #2a7de1;
  --shadow: 0 1px 2px rgba(11,20,26,.08), 0 2px 8px rgba(11,20,26,.06);
  --radius: 12px; --font-scale: 1;
  --topbar: #075e54; --topbar-ink: #ffffff;
  --warn-bg: #fff4d6; --warn-ink: #5c4100; --warn-line: #f4dd9c;
  --bad-bg: #fde7e5; --bad-ink: #7d1a12; --bad-line: #f7c4bf;
  --ok-bg: #e3f7ec; --ok-ink: #0f5c35; --ok-line: #bfe9d1;
  --info-bg: #e6f0fc; --info-ink: #174a8a; --info-line: #c4dbf6;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --brand: #00a884; --brand-2: #00a884; --accent: #25d366; --accent-ink: #04261f;
  --bg: #0b141a; --surface: #111b21; --surface-2: #1a252c; --chat-bg: #0b141a;
  --text: #e9edef; --muted: #8696a0; --border: #253139;
  --bubble: #202c33; --bubble-mine: #005c4b; --bubble-hl: #103b33;
  --shadow: 0 1px 2px rgba(0,0,0,.35);
  --topbar: #202c33; --topbar-ink: #e9edef;
  --warn-bg: #3d3214; --warn-ink: #ffe08a; --warn-line: #5a4a1c;
  --bad-bg: #3f1d1a; --bad-ink: #ffb4ab; --bad-line: #5c2a25;
  --ok-bg: #12352a; --ok-ink: #8fe0b5; --ok-line: #1d4d3c;
  --info-bg: #142a44; --info-ink: #a8c8f0; --info-line: #1f3d60;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) {
    --brand: #00a884; --brand-2: #00a884; --accent: #25d366; --accent-ink: #04261f;
    --bg: #0b141a; --surface: #111b21; --surface-2: #1a252c; --chat-bg: #0b141a;
    --text: #e9edef; --muted: #8696a0; --border: #253139;
    --bubble: #202c33; --bubble-mine: #005c4b; --bubble-hl: #103b33;
    --shadow: 0 1px 2px rgba(0,0,0,.35); --topbar: #202c33; --topbar-ink: #e9edef;
    --warn-bg: #3d3214; --warn-ink: #ffe08a; --warn-line: #5a4a1c;
    --bad-bg: #3f1d1a; --bad-ink: #ffb4ab; --bad-line: #5c2a25;
    --ok-bg: #12352a; --ok-ink: #8fe0b5; --ok-line: #1d4d3c;
    --info-bg: #142a44; --info-ink: #a8c8f0; --info-line: #1f3d60;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { font-size: calc(15px * var(--font-scale)); }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Tamil", "Latha", sans-serif;
  line-height: 1.45; -webkit-font-smoothing: antialiased;
}
a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.25; }
h1 { font-size: 1.45rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .right { text-align: right; }
.nowrap { white-space: nowrap; } .mono { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }

/* ---------- buttons & forms ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .55rem 1rem; border-radius: 999px; border: 1px solid transparent;
  background: var(--brand); color: #fff; font: inherit; font-weight: 600; cursor: pointer;
  text-decoration: none !important; min-height: 40px; transition: filter .15s, transform .05s;
}
.btn:hover { filter: brightness(1.08); } .btn:active { transform: scale(.98); }
.btn.accent { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn.danger { background: var(--danger); }
.btn.warn { background: var(--warn); color: #231a00; }
.btn.sm { padding: .3rem .7rem; min-height: 32px; font-size: .85rem; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.icon-btn { background: none; border: 0; color: inherit; cursor: pointer; padding: .4rem; border-radius: 50%; font-size: 1.2rem; line-height: 1; }
.icon-btn:hover { background: rgba(127,127,127,.15); }

label { display: block; font-size: .85rem; color: var(--muted); margin: 0 0 .3rem; font-weight: 500; }
input[type=text], input[type=tel], input[type=email], input[type=number], input[type=password], input[type=date],
input[type=search], input[type=file], select, textarea {
  width: 100%; padding: .6rem .75rem; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text); font: inherit; min-height: 42px;
}
textarea { min-height: 110px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-2); outline-offset: 0; border-color: transparent; }
.field { margin-bottom: .9rem; }
.row { display: grid; gap: .9rem; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.inline { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.check { display: flex; gap: .5rem; align-items: center; color: var(--text); font-size: .95rem; }
.check input { width: 18px; height: 18px; accent-color: var(--brand-2); }
.repeat-row { display: flex; gap: .5rem; margin-bottom: .5rem; }
.repeat-row input { flex: 1; }

/* ---------- cards, tables, badges ---------- */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem; margin-bottom: 1rem; border: 1px solid var(--border); }
.card-h { display: flex; justify-content: space-between; align-items: center; gap: .6rem; margin-bottom: .8rem; flex-wrap: wrap; }
.grid { display: grid; gap: 1rem; }
.stats { display: grid; gap: .8rem; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); margin-bottom: 1rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem; box-shadow: var(--shadow); display: block; color: var(--text); }
.stat:hover { text-decoration: none; border-color: var(--brand-2); }
.stat .n { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: .82rem; }
.stat.ok .n { color: var(--ok); } .stat.warn .n { color: var(--warn); } .stat.bad .n { color: var(--danger); } .stat.info .n { color: var(--info); }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.t { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.t th, table.t td { padding: .6rem .7rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
table.t th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: var(--surface-2); position: sticky; top: 0; }
table.t tr:hover td { background: var(--surface-2); }
table.t tfoot td { font-weight: 700; background: var(--surface-2); }

.badge { display: inline-block; padding: .12rem .55rem; border-radius: 999px; font-size: .75rem; font-weight: 600; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.badge.ACTIVE, .badge.SUCCESS, .badge.SENT, .badge.APPROVED { background: #e3f7ec; color: #116b3d; border-color: #bfe9d1; }
.badge.EXPIRING, .badge.PENDING, .badge.CREATED, .badge.PENDING_PAYMENT { background: #fff4d6; color: #7a5600; border-color: #f4dd9c; }
.badge.EXPIRED, .badge.FAILED, .badge.REJECTED, .badge.SUSPENDED { background: #fde7e5; color: #a3241a; border-color: #f7c4bf; }
.badge.LONG_INACTIVE, .badge.DEACTIVATED, .badge.REMOVED, .badge.SKIPPED, .badge.REFUNDED { background: #ebeef1; color: #4a5560; border-color: #d5dbe0; }
:root[data-theme="dark"] .badge { filter: saturate(.8) brightness(.9); }

.alert { padding: .75rem 1rem; border-radius: 10px; margin-bottom: 1rem; border: 1px solid; }
.alert.success { background: var(--ok-bg); border-color: var(--ok-line); color: var(--ok-ink); }
.alert.error { background: var(--bad-bg); border-color: var(--bad-line); color: var(--bad-ink); }
.alert.info { background: var(--info-bg); border-color: var(--info-line); color: var(--info-ink); }
.alert.warn { background: var(--warn-bg); border-color: var(--warn-line); color: var(--warn-ink); }

.pager { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .8rem; }
.pager a, .pager span { padding: .3rem .7rem; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); }
.pager .cur { background: var(--brand); color: #fff; border-color: var(--brand); }

.tabs { display: flex; gap: .3rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; overflow-x: auto; }
.tabs a { padding: .6rem .9rem; color: var(--muted); border-bottom: 3px solid transparent; white-space: nowrap; font-weight: 600; }
.tabs a.on { color: var(--brand-2); border-color: var(--brand-2); text-decoration: none; }

.price-card { background: var(--bubble-hl); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; }
.price-card .line { display: flex; justify-content: space-between; padding: .25rem 0; font-variant-numeric: tabular-nums; }
.price-card .total { border-top: 1px dashed var(--muted); margin-top: .4rem; padding-top: .5rem; font-size: 1.2rem; font-weight: 700; }

/* ---------- admin layout ---------- */
.adm { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--border); padding: 1rem .7rem; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.side .logo { display: flex; align-items: center; gap: .6rem; font-weight: 800; color: var(--brand); padding: .3rem .5rem 1rem; font-size: 1.05rem; }
.side .logo img { width: 40px; height: auto; flex: none; filter: drop-shadow(0 1px 2px rgba(0,0,0,.25)); }
.logo-full { width: 190px; max-width: 70%; height: auto; display: block; margin: 0 auto .5rem; filter: drop-shadow(0 3px 8px rgba(0,0,0,.25)); }
.logo-emb { width: 72px; height: auto; display: block; margin: 0 auto .4rem; }
.app-top .brand-emb { width: 42px; height: 42px; object-fit: contain; flex: none; filter: drop-shadow(0 1px 2px rgba(0,0,0,.35)); }
.side .logo i { width: 34px; height: 34px; border-radius: 10px; background: var(--accent); display: grid; place-items: center; color: var(--accent-ink); font-style: normal; }
.side nav a { display: flex; align-items: center; gap: .7rem; padding: .55rem .7rem; border-radius: 10px; color: var(--text); font-weight: 500; }
.side nav a:hover { background: var(--surface-2); text-decoration: none; }
.side nav a.on { background: var(--bubble-hl); color: var(--brand-2); font-weight: 700; }
.side nav .sec { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 1rem .7rem .3rem; }
.side nav .cnt { margin-left: auto; background: var(--danger); color: #fff; border-radius: 999px; font-size: .72rem; padding: 0 .45rem; }
.main { min-width: 0; }
.topbar { display: flex; align-items: center; gap: .7rem; padding: .7rem 1.2rem; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.topbar .title { font-weight: 700; flex: 1; }
.content { padding: 1.2rem; max-width: 1400px; }
.menu-toggle { display: none; }
@media (max-width: 900px) {
  .adm { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 50; left: 0; top: 0; width: 270px; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  body.nav-open .side { transform: none; }
  body.nav-open::after { content: ""; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 40; }
  .menu-toggle { display: inline-block; }
  .content { padding: .8rem; }
}

/* ---------- auth pages ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 1rem;
  background: linear-gradient(180deg, var(--brand) 0 220px, var(--bg) 220px); }
.auth .box { width: 100%; max-width: 400px; background: var(--surface); border-radius: 16px; box-shadow: 0 8px 30px rgba(0,0,0,.12); padding: 1.6rem; }
.auth .brand { text-align: center; margin-bottom: 1.2rem; }
.auth .brand .ico { width: 64px; height: 64px; margin: 0 auto .6rem; border-radius: 18px; background: var(--accent); display: grid; place-items: center; font-size: 2rem; }
.otp-input { letter-spacing: .6em; text-align: center; font-size: 1.4rem !important; font-weight: 700; }

/* ---------- user portal (WhatsApp-style) ---------- */
.app { max-width: 900px; margin: 0 auto; min-height: 100vh; background: var(--chat-bg); display: flex; flex-direction: column; box-shadow: var(--shadow); }
.app-top { background: var(--topbar); color: var(--topbar-ink); padding: .65rem 1rem; display: flex; align-items: center; gap: .8rem; position: sticky; top: 0; z-index: 30; }
.app-top .avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-weight: 800; flex: none; }
.app-top .who { flex: 1; min-width: 0; }
.app-top .who b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-top .who span { font-size: .8rem; opacity: .85; }
.app-top a, .app-top .icon-btn { color: var(--topbar-ink); }
.app-body { flex: 1; padding: .8rem .8rem 90px; }
.app-tabs { position: fixed; bottom: 0; left: 50%; transform: translateX(-50%); width: 100%; max-width: 900px; display: flex; background: var(--surface); border-top: 1px solid var(--border); z-index: 30; padding-bottom: env(safe-area-inset-bottom); }
.app-tabs a { flex: 1; text-align: center; padding: .5rem 0 .55rem; color: var(--muted); font-size: .75rem; font-weight: 600; position: relative; }
.app-tabs a span { display: block; font-size: 1.3rem; line-height: 1.3; }
.app-tabs a.on { color: var(--brand-2); text-decoration: none; }
.app-tabs a.on::before { content: ""; position: absolute; top: 0; left: 30%; right: 30%; height: 3px; border-radius: 0 0 3px 3px; background: var(--brand-2); }
.app-tabs .dot { position: absolute; top: 4px; left: calc(50% + 6px); background: var(--accent); color: var(--accent-ink); border-radius: 999px; font-size: .65rem; padding: 0 .35rem; }

.chat-bg { background-color: var(--chat-bg);
  background-image: radial-gradient(rgba(127,127,127,.07) 1px, transparent 1px); background-size: 18px 18px; }
.status-chip { display: inline-flex; align-items: center; gap: .35rem; font-size: .78rem; font-weight: 700; padding: .25rem .65rem; border-radius: 999px; background: rgba(255,255,255,.18); }
.status-chip::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.status-chip.EXPIRING::before { background: #ffcc33; } .status-chip.EXPIRED::before, .status-chip.LONG_INACTIVE::before, .status-chip.PENDING::before { background: #ff6b5e; }

.banner { display: flex; gap: .8rem; align-items: center; padding: .8rem 1rem; border-radius: var(--radius); margin-bottom: .8rem; box-shadow: var(--shadow); }
.banner.warn { background: var(--warn-bg); color: var(--warn-ink); } .banner.bad { background: var(--bad-bg); color: var(--bad-ink); }
.banner .grow { flex: 1; }

.current { background: var(--bubble); border-radius: 16px; box-shadow: var(--shadow); padding: 1rem 1.1rem; margin-bottom: 1rem; border-left: 5px solid var(--accent); position: relative; }
.current .tag { position: absolute; top: -10px; right: 14px; background: var(--accent); color: var(--accent-ink); font-size: .7rem; font-weight: 800; padding: .15rem .6rem; border-radius: 999px; letter-spacing: .04em; }
.current .meta { display: flex; flex-wrap: wrap; gap: .4rem .9rem; font-size: .82rem; color: var(--muted); margin-bottom: .6rem; }
.current .meta b { color: var(--text); }
.current .text { white-space: pre-wrap; word-wrap: break-word; font-size: 1.08rem; }
.current .actions { display: flex; gap: .5rem; margin-top: .8rem; }

.day-sep { text-align: center; margin: 1rem 0 .6rem; }
.day-sep span { background: var(--surface); color: var(--muted); font-size: .75rem; font-weight: 600; padding: .25rem .8rem; border-radius: 8px; box-shadow: var(--shadow); }
.bubble { background: var(--bubble); border-radius: 0 12px 12px 12px; padding: .55rem .75rem .35rem; margin: 0 0 .5rem; max-width: 92%; box-shadow: var(--shadow); position: relative; }
.bubble::before { content: ""; position: absolute; left: -7px; top: 0; border: 7px solid transparent; border-top-color: var(--bubble); border-right-color: var(--bubble); }
.bubble.unread { border-left: 3px solid var(--accent); }
.bubble .cl { font-size: .76rem; font-weight: 700; color: var(--brand-2); margin-bottom: .2rem; }
.bubble .txt { white-space: pre-wrap; word-wrap: break-word; }
.bubble .tm { text-align: right; font-size: .7rem; color: var(--muted); margin-top: .15rem; }
.bubble mark { background: #ffe066; color: #000; padding: 0 2px; border-radius: 3px; }
.search-bar { display: flex; gap: .5rem; margin-bottom: .8rem; }
.empty { text-align: center; color: var(--muted); padding: 2.5rem 1rem; }
.empty .ico { font-size: 2.6rem; }

.list-item { display: flex; align-items: center; gap: .8rem; padding: .8rem 0; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: 0; }
.list-item .grow { flex: 1; min-width: 0; }

.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: #323232; color: #fff; padding: .6rem 1.1rem; border-radius: 999px; font-size: .9rem; z-index: 99; opacity: 0; transition: opacity .2s; pointer-events: none; }
.toast.show { opacity: 1; }

.theme-switch { display: inline-flex; border: 1px solid var(--border); border-radius: 999px; overflow: hidden; }
.theme-switch button { background: transparent; border: 0; padding: .4rem .8rem; color: var(--text); cursor: pointer; font: inherit; font-size: .85rem; }
.theme-switch button.on { background: var(--brand-2); color: #fff; }

dialog { border: 0; border-radius: 16px; padding: 1.2rem; background: var(--surface); color: var(--text); max-width: 480px; width: calc(100% - 2rem); box-shadow: 0 10px 40px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(0,0,0,.45); }

@media print { .side, .topbar, .app-tabs, .no-print { display: none !important; } .adm { display: block; } }
