/* ──────────────────────────────────────────────────────────────────────────
   Kotak Neo Trading — design system
   ────────────────────────────────────────────────────────────────────────── */
:root {
  --bg:        #f4f6fb;
  --surface:   #ffffff;
  --ink:       #0f172a;
  --ink-soft:  #475569;
  --muted:     #94a3b8;
  --line:      #e5e9f2;

  --brand:     #4f46e5;
  --brand-2:   #7c3aed;
  --brand-ink: #ffffff;
  --accent:    #06b6d4;

  --ok:        #16a34a;
  --warn:      #ea580c;
  --bad:       #dc2626;

  --shadow-sm: 0 1px 2px rgba(15,23,42,.05);
  --shadow:    0 4px 24px rgba(15,23,42,.08);
  --shadow-lg: 0 20px 60px rgba(15,23,42,.18);

  --r-sm: 6px;
  --r:    10px;
  --r-lg: 16px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter",
               Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
  line-height: 1.5;
}

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

code {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 12px; color: var(--ink-soft);
  background: #eef2f9; padding: 1px 6px; border-radius: 4px;
}

h1, h2, h3 { margin: 0 0 .5em; color: var(--ink); }
h1 { font-size: 22px; font-weight: 700; }
h2 { font-size: 18px; font-weight: 700; }
h3 { font-size: 15px; font-weight: 600; }

/* ── App shell (sidebar + content) ─────────────────────────────────────── */
body.app {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: linear-gradient(180deg, #0f172a 0%, #1e293b 100%);
  color: #cbd5e1;
  display: flex; flex-direction: column;
  padding: 24px 16px;
  position: sticky; top: 0; height: 100vh;
}

.brand {
  display: flex; align-items: center; gap: 12px;
  padding: 0 4px 24px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  margin-bottom: 20px;
}
.brand-mark {
  width: 36px; height: 36px; border-radius: 8px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  display: grid; place-items: center;
  color: #fff; font-weight: 800; font-size: 14px;
  letter-spacing: .5px;
  box-shadow: 0 4px 12px rgba(79,70,229,.4);
}
.brand-mark.large { width: 48px; height: 48px; font-size: 18px; }
.brand-title { color: #fff; font-weight: 700; font-size: 15px; }
.brand-sub   { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 1px; }

.side-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.side-nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  color: #cbd5e1;
  border-radius: var(--r-sm);
  font-size: 14px;
  transition: all .15s;
}
.side-nav a:hover {
  background: rgba(255,255,255,.06);
  color: #fff; text-decoration: none;
}
.side-nav a.active {
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff;
  box-shadow: 0 4px 12px rgba(79,70,229,.35);
}
.side-nav .ic {
  font-size: 16px; width: 18px; text-align: center;
  display: inline-block;
}

.side-foot {
  border-top: 1px solid rgba(255,255,255,.08);
  padding-top: 16px;
  display: flex; flex-direction: column; gap: 12px;
}
.who { display: flex; align-items: center; gap: 10px; padding: 4px; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--brand));
  display: grid; place-items: center;
  color: #fff; font-weight: 700;
}
.who-name { color: #fff; font-size: 13px; font-weight: 600; }
.who-role { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .5px; }
.logout {
  text-align: center; padding: 8px;
  color: #cbd5e1; border: 1px solid rgba(255,255,255,.12);
  border-radius: var(--r-sm); font-size: 13px;
}
.logout:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }

/* ── Main content area ────────────────────────────────────────────────── */
.content { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 32px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { margin: 0; }
.page { padding: 28px 32px; }

/* ── Cards & forms ────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--r);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--line);
  margin-bottom: 20px;
}
.card.narrow { max-width: 460px; }
.card h2:first-child, .card h3:first-child { margin-top: 0; }

label {
  display: block; margin: 14px 0 6px;
  font-size: 12px; font-weight: 600; color: var(--ink-soft);
  text-transform: uppercase; letter-spacing: .5px;
}
input, select, textarea {
  width: 100%; padding: 10px 12px; font-size: 14px;
  border: 1px solid var(--line); border-radius: var(--r-sm);
  background: #fff; color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(79,70,229,.15);
}
input::placeholder { color: var(--muted); }

.pwd-wrap { position: relative; }
.pwd-wrap input { padding-right: 40px; }
.pwd-toggle {
  position: absolute; top: 50%; right: 4px;
  transform: translateY(-50%);
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; padding: 0;
  background: transparent; border: none; cursor: pointer;
  color: var(--muted);
}
.pwd-toggle:hover { background: transparent; color: var(--ink); }
.pwd-toggle svg { display: block; }

button {
  padding: 8px 16px; font-size: 13px; font-weight: 500; cursor: pointer;
  border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--surface); color: var(--ink);
  transition: all .15s;
}
button:hover { background: #eef2f9; }
button.primary {
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: var(--brand-ink); border-color: transparent;
  box-shadow: 0 2px 8px rgba(79,70,229,.3);
}
button.primary:hover {
  filter: brightness(1.05);
  box-shadow: 0 4px 14px rgba(79,70,229,.4);
}
button.danger {
  background: var(--bad); color: #fff; border-color: transparent;
}
button.danger:hover { filter: brightness(.95); }
button.block { width: 100%; padding: 12px; font-size: 14px; font-weight: 600; margin-top: 8px; }

/* ── Flash messages ───────────────────────────────────────────────────── */
.flash {
  padding: 12px 16px; border-radius: var(--r-sm); margin-bottom: 14px;
  font-size: 14px; border-left: 4px solid;
}
.flash-success { background: #f0fdf4; color: #14532d; border-color: var(--ok); }
.flash-error   { background: #fef2f2; color: #7f1d1d; border-color: var(--bad); }
.flash-info    { background: #eff6ff; color: #1e3a8a; border-color: #3b82f6; }

/* ── Tables ───────────────────────────────────────────────────────────── */
table.grid {
  width: 100%; border-collapse: collapse;
  background: var(--surface);
  border-radius: var(--r); overflow: hidden;
  box-shadow: var(--shadow-sm); border: 1px solid var(--line);
}
table.grid th, table.grid td {
  padding: 12px 14px; border-bottom: 1px solid var(--line);
  font-size: 13px; text-align: left; vertical-align: middle;
}
table.grid th {
  background: #f8fafc; font-weight: 600;
  font-size: 11px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--ink-soft);
}
table.grid tr:last-child td { border-bottom: none; }
table.grid tr:hover { background: #f8fafc; }

table.grid .actions { display: flex; gap: 6px; flex-wrap: wrap; }
table.grid .actions form { display: inline; margin: 0; }
table.grid .actions button { padding: 6px 10px; font-size: 12px; }

/* ── Pills, badges, helpers ───────────────────────────────────────────── */
.pill {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px;
}
.pill-ok   { background: #dcfce7; color: #14532d; }
.pill-bad  { background: #fee2e2; color: #7f1d1d; }
.pill-info { background: #e0e7ff; color: #312e81; }
.pill-warn { background: #ffedd5; color: #7c2d12; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.ok    { color: var(--ok); }
.bad   { color: var(--bad); }
.buy   { color: var(--ok); font-weight: 600; }
.sell  { color: var(--bad); font-weight: 600; }
.row   { display: flex; gap: 16px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 240px; }
.hr     { height: 1px; background: var(--line); margin: 20px 0; border: 0; }

.pager { margin-top: 16px; text-align: center; color: var(--ink-soft); }
.pager a { margin: 0 12px; font-weight: 500; }

.ta-right { text-align: right; }
.actions.ta-right { justify-content: flex-end; }

/* ── Stat cards (dashboard overview) ──────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}
.stat-card {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  color: var(--ink);
  transition: transform .15s, box-shadow .15s;
}
a.stat-card:hover {
  text-decoration: none;
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.stat-icon {
  width: 44px; height: 44px; border-radius: 10px;
  display: grid; place-items: center;
  color: #fff; font-size: 18px;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(0,0,0,.1);
}
.stat-body { min-width: 0; }
.stat-num   { font-size: 26px; font-weight: 700; line-height: 1.1; color: var(--ink); }
.stat-label { font-size: 12px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .5px; margin-top: 2px; }

/* ── Login (auth page) ────────────────────────────────────────────────── */
body.auth-page {
  min-height: 100vh;
  display: grid; place-items: center;
  background:
    radial-gradient(900px 600px at 0% 0%, #6366f1 0%, transparent 60%),
    radial-gradient(800px 700px at 100% 100%, #06b6d4 0%, transparent 55%),
    linear-gradient(135deg, #0f172a 0%, #1e1b4b 50%, #312e81 100%);
  padding: 24px;
}
.auth-shell {
  width: 100%; max-width: 920px;
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  display: grid; grid-template-columns: 1fr 1fr;
}
.auth-side {
  padding: 48px 40px;
  color: #fff;
  background: linear-gradient(160deg, #4f46e5 0%, #7c3aed 60%, #312e81 100%);
}
.auth-logo {
  display: flex; align-items: center; gap: 14px; margin-bottom: 40px;
}
.auth-brand-title { font-weight: 700; font-size: 18px; }
.auth-brand-sub   { font-size: 12px; opacity: .8; text-transform: uppercase; letter-spacing: 1px; }
.auth-side h2 {
  color: #fff; font-size: 26px; line-height: 1.25; font-weight: 700;
  margin-bottom: 24px;
}
.auth-bullets {
  list-style: none; padding: 0; margin: 0;
  display: flex; flex-direction: column; gap: 12px;
}
.auth-bullets li {
  padding-left: 24px; position: relative;
  font-size: 14px; opacity: .95;
}
.auth-bullets li:before {
  content: "✓"; position: absolute; left: 0; top: 0;
  width: 18px; height: 18px; border-radius: 50%;
  background: rgba(255,255,255,.18);
  display: grid; place-items: center;
  font-size: 11px; font-weight: 700;
}

.auth-card { padding: 48px 40px; display: flex; flex-direction: column; justify-content: center; }
.auth-card h1 { font-size: 24px; }
.auth-sub { color: var(--ink-soft); margin: 0 0 24px; }
.auth-form label { margin-top: 12px; }
.auth-foot { margin-top: 20px; font-size: 12px; color: var(--muted); text-align: center; }

/* ──────────────────────────────────────────────────────────────────────────
   Responsive layer
   Breakpoints (mirror Bootstrap/Tailwind so they're predictable):
     sm  ≥ 640px
     md  ≥ 768px
     lg  ≥ 1024px
     xl  ≥ 1280px
   New pages: wrap wide tables in <div class="table-scroll">.
              Use .row for fluid columns, .show-md / .hide-md for visibility.
   ────────────────────────────────────────────────────────────────────────── */

/* Hamburger button — visible only on mobile */
.sidebar-toggle {
  display: none;
  align-items: center; justify-content: center;
  width: 40px; height: 40px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-sm); padding: 0; cursor: pointer;
  color: var(--ink-soft);
}
.sidebar-toggle:hover { background: #eef2f9; color: var(--ink); }
.sidebar-toggle svg { display: block; }

/* Sidebar drawer overlay backdrop (mobile only) */
.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(15,23,42,.55);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  z-index: 90;
  animation: modal-fade .15s ease;
}
body.sidebar-open .sidebar-backdrop { display: block; }

/* Table horizontal scroll wrapper — keeps wide tables usable on phones.
   Apply to any wide table: <div class="table-scroll"><table class="grid">…</table></div> */
.table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--r);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  background: var(--surface);
}
.table-scroll table.grid {
  border: none;
  border-radius: 0;
  box-shadow: none;
  margin: 0;
  min-width: 100%;
}

/* Visibility utilities (mobile-first: shown by default at small screens) */
.show-md { display: none; }   /* hidden until md+ */
.hide-md { display: initial; } /* hidden at md+    */
.show-sm-block { display: block; }
.hide-sm-block { display: block; }

/* ── Auth (collapse on phones) ───────────────────────────────────────── */
@media (max-width: 759px) {
  .auth-shell { grid-template-columns: 1fr; }
  .auth-side  { display: none; }
}

/* ── Mobile (<768px): sidebar drawer + dense layout ──────────────────── */
@media (max-width: 767px) {
  body.app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0;
    width: 280px; max-width: 85vw;
    height: 100vh;
    transform: translateX(-100%);
    transition: transform .25s ease;
    z-index: 100;
  }
  body.sidebar-open .sidebar { transform: translateX(0); }
  .sidebar-toggle { display: inline-flex; }

  /* Visibility utility flips */
  .show-md       { display: initial; }
  .hide-md       { display: none; }

  /* Density */
  .topbar { padding: 12px 14px; gap: 10px; flex-wrap: wrap; }
  .topbar h1 { font-size: 18px; flex: 1 1 auto; min-width: 0; }
  .page { padding: 16px 14px; }

  .card { padding: 16px; }
  h1 { font-size: 20px; }
  h2 { font-size: 16px; }
  h3 { font-size: 14px; }

  /* .row children take full width on phones */
  .row > * { min-width: 100%; flex-basis: 100%; }

  /* Stat grid: 2 columns on mobile (auto-fit was minmax 220 = 1 col) */
  .stat-grid { grid-template-columns: 1fr; gap: 12px; }
  .stat-num  { font-size: 22px; }

  /* Tables: smaller padding + slightly smaller font */
  table.grid th, table.grid td { padding: 9px 10px; font-size: 12px; }
  table.grid .actions button { padding: 5px 8px; font-size: 11px; }

  /* Tab strip: tight wrapping */
  .tab-strip { padding: 4px; }
  .tab-strip .tab { padding: 6px 10px; font-size: 12px; }
}

/* ── Tablet (≥ md / 768px): default behaviour ─────────────────────────── */
@media (min-width: 768px) {
  .show-md       { display: initial; }
  .hide-md       { display: none; }
}

/* ── Large desktop (≥ xl / 1280px): roomier padding ───────────────────── */
@media (min-width: 1280px) {
  .page { padding: 32px 48px; }
}

/* ── Row action menu (popover) ───────────────────────────────────────── */
.menu { position: relative; display: inline-block; }
.menu-trigger {
  display: inline-flex; align-items: center; gap: 6px;
}
.menu-trigger .caret { font-size: 10px; opacity: .8; }
.menu-pop {
  /* Position is set in JS via getBoundingClientRect so the popover escapes
     any ancestor with `overflow: hidden` (e.g. .grid table). */
  position: fixed;
  min-width: 200px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  padding: 4px;
  z-index: 1100;
  animation: menu-pop .12s ease;
}
.menu-pop form { display: block; margin: 0; }
.menu-item, .menu-pop button, .menu-pop a {
  display: block; width: 100%; box-sizing: border-box;
  padding: 8px 12px; text-align: left;
  border: none; border-radius: var(--r-sm);
  background: transparent; color: var(--ink);
  font-size: 13px; font-family: inherit; font-weight: 500;
  cursor: pointer; text-decoration: none;
  transition: background .12s, color .12s;
}
.menu-pop button:hover,
.menu-pop a:hover { background: #eef2f9; color: var(--ink); text-decoration: none; }
.menu-pop .menu-item.danger,
.menu-pop button.danger { color: var(--bad); background: transparent; }
.menu-pop .menu-item.danger:hover,
.menu-pop button.danger:hover { background: #fef2f2; color: var(--bad); }
.menu-sep {
  height: 1px; background: var(--line); margin: 4px 0;
}
.menu-label {
  padding: 6px 12px 2px;
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .5px; color: var(--muted);
}
@keyframes menu-pop {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Tab strip (segment switcher / etc.) ─────────────────────────────── */
.tab-strip {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 6px; background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow-sm);
}
.tab-strip .tab {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px; border-radius: var(--r-sm);
  color: var(--ink-soft); font-size: 13px; font-weight: 500;
  text-decoration: none;
  transition: background .15s, color .15s;
}
.tab-strip .tab:hover { background: #eef2f9; color: var(--ink); text-decoration: none; }
.tab-strip .tab.active {
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff;
  box-shadow: 0 2px 8px rgba(79,70,229,.3);
}
.tab-strip .tab-count {
  display: inline-block; min-width: 22px; text-align: center;
  padding: 1px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 700;
  background: #eef2f9; color: var(--ink-soft);
}
.tab-strip .tab.active .tab-count {
  background: rgba(255,255,255,.22); color: #fff;
}

/* ── Modal (themed confirm / prompt) ─────────────────────────────────── */
.modal-root {
  position: fixed; inset: 0; z-index: 1000;
  display: none;
  align-items: center; justify-content: center;
  padding: 20px;
}
.modal-root.open { display: flex; }
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(15,23,42,.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: modal-fade .15s ease;
}
.modal-card {
  position: relative;
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  width: 100%; max-width: 440px;
  overflow: hidden;
  animation: modal-pop .18s cubic-bezier(.2,.8,.2,1);
  border: 1px solid var(--line);
}
.modal-accent {
  height: 4px;
  background: linear-gradient(90deg, var(--brand), var(--brand-2));
}
.modal-accent.danger { background: var(--bad); }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px 8px;
}
.modal-title { margin: 0; font-size: 16px; font-weight: 700; color: var(--ink); }
.modal-close {
  background: transparent; border: none; padding: 0;
  width: 28px; height: 28px; border-radius: var(--r-sm);
  font-size: 22px; line-height: 1; color: var(--muted); cursor: pointer;
  transition: all .15s;
}
.modal-close:hover { background: #eef2f9; color: var(--ink); }
.modal-body {
  padding: 4px 22px 8px;
  color: var(--ink-soft); font-size: 14px;
}
.modal-message { margin: 0 0 4px; line-height: 1.55; }
.modal-input-label {
  display: block; margin: 12px 0 6px;
  font-size: 12px; font-weight: 600; color: var(--ink-soft);
  text-transform: uppercase; letter-spacing: .5px;
}
.modal-input {
  width: 100%; padding: 10px 12px; font-size: 14px;
  border: 1px solid var(--line); border-radius: var(--r-sm);
  background: #fff; color: var(--ink);
  font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
}
.modal-input:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(79,70,229,.15);
}
.modal-input.invalid {
  border-color: var(--bad);
  box-shadow: 0 0 0 3px rgba(220,38,38,.12);
}
.modal-error { color: var(--bad); font-size: 12px; margin: 6px 0 0; min-height: 16px; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 16px 22px 20px;
}
@keyframes modal-fade {
  from { opacity: 0; } to { opacity: 1; }
}
@keyframes modal-pop {
  from { opacity: 0; transform: translateY(8px) scale(.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
