/* app.css — NirmaanCRM design system.
   Mobile-first. Phones: top bar + bottom tabs. Desktop (>= 900px): sidebar + content.
   Brand colour comes from /brand/theme.css (--brand); everything else derives from it. */

:root {
  --brand: #1d4ed8;
  --brand-dark: color-mix(in srgb, var(--brand) 80%, #000);
  --brand-soft: color-mix(in srgb, var(--brand) 9%, #fff);
  --bg: #f4f6f9;
  --surface: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --success: #15803d;
  --warning: #b45309;
  --danger: #dc2626;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .05);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, .18);
  --sidebar-w: 256px;
  --btn-h: 48px;
  /* legacy names still used by older screens */
  --white: #fff; --card-bg: var(--surface);
}

* { box-sizing: border-box; }
html { font-size: 17px; -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text); line-height: 1.5;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Devanagari", Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent; -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); }
h1 { font-size: 1.55rem; line-height: 1.2; margin: 0 0 16px; font-weight: 750; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; margin: 0 0 4px; font-weight: 700; }
h3 { font-size: .8rem; margin: 22px 0 8px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
p { margin: 0 0 10px; }
svg.i { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- App shell ---------- */
.app { display: flex; min-height: 100vh; }
.content { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.main { flex: 1; width: 100%; max-width: 1180px; margin: 0 auto; padding: 18px 16px 110px; }

.topbar {
  position: sticky; top: 0; z-index: 90; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 14px; background: var(--surface); border-bottom: 1px solid var(--border); min-height: 60px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo-mark {
  width: 36px; height: 36px; border-radius: 10px; background: var(--brand); color: #fff; display: grid; place-items: center;
  font-weight: 800; flex: none; overflow: hidden;
}
.logo-mark img { width: 100%; height: 100%; object-fit: cover; }
.trade-name { font-weight: 750; font-size: 1.02rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-right { display: flex; align-items: center; gap: 6px; position: relative; }
.icon-btn {
  position: relative; width: 44px; height: 44px; display: grid; place-items: center; border-radius: 12px; border: 0;
  background: transparent; color: var(--text); cursor: pointer;
}
.icon-btn:hover { background: var(--bg); }
.notify-badge {
  position: absolute; top: 4px; right: 2px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; display: none; align-items: center; justify-content: center;
}
.avatar {
  width: 38px; height: 38px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); font-weight: 750; font-size: .85rem;
  display: grid; place-items: center; border: 1px solid color-mix(in srgb, var(--brand) 22%, #fff);
}
.user-menu {
  position: absolute; right: 0; top: 52px; min-width: 230px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow-lg); z-index: 200; padding: 6px; display: none;
}
.user-menu .who { padding: 10px 12px 8px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.user-menu .who b { display: block; }
.user-menu .who span { color: var(--muted); font-size: .85rem; }
.menu-item { display: flex; align-items: center; gap: 10px; padding: 11px 12px; border-radius: 8px; cursor: pointer; font-size: .95rem; }
.menu-item:hover { background: var(--bg); }
.menu-item.danger { color: var(--danger); }

/* sidebar (desktop only) */
.sidebar { display: none; }
.side-brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; }
.side-nav { flex: 1; overflow-y: auto; padding: 4px 12px 12px; }
.side-group { font-size: .68rem; text-transform: uppercase; letter-spacing: .09em; color: var(--muted); font-weight: 700; padding: 16px 10px 6px; }
.side-link {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; margin: 2px 0; border-radius: 10px; color: #334155;
  text-decoration: none; font-weight: 600; font-size: .93rem; cursor: pointer;
}
.side-link:hover { background: var(--bg); }
.side-link.active { background: var(--brand-soft); color: var(--brand); }
.side-foot { padding: 12px 14px; border-top: 1px solid var(--border); font-size: .8rem; color: var(--muted); }

/* bottom tabs (phones) */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 80; display: flex; background: var(--surface);
  border-top: 1px solid var(--border); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 2px; font-size: .68rem; font-weight: 650;
  color: var(--muted); text-decoration: none; border-radius: 10px; min-width: 0;
}
.nav-item span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item.active { color: var(--brand); }
.nav-item.active svg { stroke-width: 2.3; }

body.guest .sidebar, body.guest .topbar, body.guest .bottom-nav { display: none !important; }
body.guest .main { padding-bottom: 30px; max-width: none; }

@media (min-width: 700px) { .tile-value { font-size: 1.85rem; } }
@media (max-width: 699px) { .dashboard-tile { padding: 12px 12px 12px 16px; } .dashboard-tile .ico { display: none; } .tile-label { font-size: .68rem; padding-right: 0; } }
@media (min-width: 900px) {
  html { font-size: 15.5px; }
  :root { --btn-h: 42px; }
  .sidebar {
    display: flex; flex-direction: column; width: var(--sidebar-w); flex: none; position: sticky; top: 0; height: 100vh;
    background: var(--surface); border-right: 1px solid var(--border);
  }
  .bottom-nav { display: none; }
  .main { padding: 28px 36px 56px; }
  .topbar { padding: 10px 28px; }
  .topbar .brand { visibility: hidden; }
  h1 { font-size: 1.7rem; margin-bottom: 20px; }
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: var(--btn-h); padding: 0 20px;
  border-radius: 11px; font-weight: 650; font-size: 1rem; line-height: 1.1; font-family: inherit; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); cursor: pointer; text-decoration: none; transition: background .12s, border-color .12s, box-shadow .12s;
  box-shadow: var(--shadow);
}
.btn:hover { background: var(--bg); border-color: #cbd5e1; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible, .icon-btn:focus-visible, .side-link:focus-visible, .nav-item:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--brand) 40%, transparent); outline-offset: 1px;
}
.btn-primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn-full { width: 100%; }
.btn.small { min-height: 38px; padding: 0 14px; font-size: .88rem; box-shadow: none; }
.btn[disabled] { opacity: .55; pointer-events: none; }

/* ---------- Forms ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; margin-bottom: 6px; font-weight: 650; font-size: .9rem; color: #334155; }
input, select, textarea { font-family: inherit; color: inherit; }
.field input, .field select, .field textarea, .modal select, .modal textarea, .modal input[type=text], .modal input[type=date], .modal input[type=email], .modal input[type=tel], .modal input[type=number], .modal input[type=url] {
  width: 100%; min-height: var(--btn-h); padding: 10px 14px; font-size: 1rem; border: 1px solid var(--border); border-radius: 11px;
  background: var(--surface);
}
.field input[type=color] { padding: 4px; width: 90px; }
.field input[type=file], .modal input[type=file] { padding: 8px; width: 100%; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--brand); }
textarea { min-height: 90px; resize: vertical; }
.password-input { position: relative; display: flex; align-items: center; }
.password-input input { padding-right: 70px; }
.password-input button { position: absolute; right: 8px; background: none; border: 0; color: var(--brand); font-weight: 650; font-size: .85rem; padding: 6px 8px; cursor: pointer; }
.check { display: flex; gap: 10px; align-items: center; font-weight: 500; cursor: pointer; }
.check input { width: 22px; height: 22px; min-height: 0; accent-color: var(--brand); }
.error { color: var(--danger); margin: 8px 0; font-size: .92rem; background: #fef2f2; border: 1px solid #fecaca; padding: 8px 12px; border-radius: 10px; }
.help { font-size: .88rem; color: var(--muted); margin: 6px 0 0; line-height: 1.5; }
.muted { color: var(--muted); font-size: .88rem; margin: 0; }

/* ---------- Cards, chips, lists ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.card.clickable { cursor: pointer; transition: box-shadow .12s, border-color .12s, transform .12s; }
.card.clickable:hover { border-color: color-mix(in srgb, var(--brand) 40%, var(--border)); box-shadow: 0 4px 14px rgba(15,23,42,.1); }
.card h2, .card h3 { margin: 0 0 2px; text-transform: none; letter-spacing: 0; color: var(--text); font-size: 1.05rem; }
.row { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.row > :first-child { min-width: 0; }
.row-btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; margin-bottom: 18px; }
.chip { display: inline-block; padding: 3px 11px; border-radius: 999px; font-size: .78rem; font-weight: 650; white-space: nowrap; text-transform: capitalize; background: #e2e8f0; }
.empty-state { background: var(--surface); border: 1px dashed #cbd5e1; border-radius: var(--radius); padding: 28px 18px; text-align: center; color: var(--muted); }
.tile-btn { padding: 22px 12px; text-align: center; line-height: 1.35; flex-direction: column; }
.subtitle { color: var(--muted); margin-bottom: 18px; }

/* Desktop: lists become responsive grids */
.main [id$="-list"], .main [id$="-log"] { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; align-items: start; }
.main [id$="-list"] > *:not(.card), .main [id$="-log"] > *:not(.card) { grid-column: 1 / -1; }
.main [id$="-list"] > h3, .main [id$="-log"] > h3 { margin: 14px 0 0; }
.main [id$="-list"] > .card, .main [id$="-log"] > .card { margin: 0 !important; }
#settings-list, #email-box, #branding-form { display: block; max-width: 620px; }
#email-box, #settings-list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }

/* ---------- Dashboard ---------- */
.hero { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.hero h1 { margin: 0; }
.hero .date { color: var(--muted); font-size: .9rem; }
.dashboard-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 700px) { .dashboard-grid { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px; } }
.dashboard-tile {
  position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px;
  box-shadow: var(--shadow); cursor: pointer; transition: transform .12s, box-shadow .12s; overflow: hidden;
}
.dashboard-tile:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(15,23,42,.1); }
.dashboard-tile::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--tone, var(--brand)); }
.dashboard-tile .ico { position: absolute; right: 14px; top: 14px; color: var(--tone, var(--brand)); opacity: .85; }
.tile-label { font-size: .8rem; color: var(--muted); font-weight: 650; text-transform: uppercase; letter-spacing: .05em; padding-right: 30px; }
.tile-value { font-size: 1.45rem; font-weight: 800; margin-top: 6px; letter-spacing: -.02em; }
.tile-sub { font-size: .85rem; color: var(--muted); margin-top: 2px; }
.tone-good { --tone: #16a34a; } .tone-warn { --tone: #d97706; } .tone-bad { --tone: #dc2626; } .tone-info { --tone: #0284c7; }

/* ---------- Login ---------- */
body.guest { background: linear-gradient(160deg, color-mix(in srgb, var(--brand) 14%, #fff), var(--bg) 55%); }
.login-card {
  max-width: 440px; margin: 7vh auto 0; padding: 28px 24px; background: var(--surface); border-radius: 20px;
  box-shadow: var(--shadow-lg); border: 1px solid var(--border);
}
.login-card .brand { justify-content: center; margin-bottom: 8px; }
.login-card .logo-mark { width: 52px; height: 52px; font-size: 1.4rem; border-radius: 14px; }
.login-card h1 { text-align: center; margin-bottom: 18px; }
.login-card .sub { text-align: center; color: var(--muted); margin: -8px 0 18px; }

/* ---------- Modal (bottom sheet on phones) ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .5); z-index: 500; overflow-y: auto; display: flex; align-items: flex-end;
  justify-content: center; backdrop-filter: blur(2px);
}
.modal {
  background: var(--surface); width: 100%; max-width: 560px; padding: 20px 18px calc(18px + env(safe-area-inset-bottom)); max-height: 92vh; overflow-y: auto;
  border-radius: 20px 20px 0 0; animation: sheet .18s ease-out;
}
@keyframes sheet { from { transform: translateY(24px); opacity: .4; } to { transform: none; opacity: 1; } }
.modal h2 { font-size: 1.25rem; margin-bottom: 8px; }
.modal h3 { margin-top: 18px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
.modal-actions .btn { flex: 1 1 auto; }
@media (min-width: 700px) {
  .modal-overlay { align-items: center; padding: 24px; }
  .modal { border-radius: 18px; box-shadow: var(--shadow-lg); animation: none; }
  .modal-actions .btn { flex: 0 0 auto; }
}
.tempbox { font: 700 1.7rem/1.2 ui-monospace, Menlo, Consolas, monospace; letter-spacing: 3px; background: var(--brand-soft); padding: 18px; border-radius: 12px; text-align: center; user-select: all; margin: 12px 0; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); transform: translateX(-50%); max-width: min(92vw, 520px);
  background: #0f172a; color: #fff; padding: 12px 18px; border-radius: 12px; z-index: 900; display: none; font-size: .95rem; box-shadow: var(--shadow-lg);
}
@media (min-width: 900px) { .toast { bottom: 28px; } }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

.help + .btn, .help + .row-btns { margin-top: 12px; }
h1 + .help { margin: -8px 0 14px; }
