:root {
  --cgh-blue: #1a5fb4;
  --cgh-blue-deep: #0d3b7a;
  --cgh-purple: #6c3fc5;
  --cgh-orange: #e67e22;
  --cgh-orange-soft: #f5c18a;
  --bg: #f4f7fb;
  --surface: #ffffff;
  --text: #1c2333;
  --muted: #5c6b7a;
  --border: #d8e0ea;
  --positive: #1b8a4a;
  --negative: #c0392b;
  --warn: #d35400;
  --share-bg: #faf6ff;
  --share-border: #c9b3ef;
  --radius: 12px;
  --shadow: 0 8px 24px rgba(13, 59, 122, 0.08);
  --font: "Segoe UI", "Source Sans 3", "Nunito Sans", system-ui, sans-serif;
  --font-display: "Segoe UI Semibold", "Segoe UI", system-ui, sans-serif;
  --sidebar-width: 260px;
  --tap: 44px;
  --topbar-h: 56px;
}

*,
*::before,
*::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(108, 63, 197,.08), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(230, 126, 34, .10), transparent 50%),
    linear-gradient(180deg, #eef3f9 0%, var(--bg) 40%, #e9eef6 100%);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 100%;
  overflow-x: hidden;
}
body.nav-open { overflow: hidden; }

img, svg, video, canvas { max-width: 100%; height: auto; }

a { color: var(--cgh-blue); text-decoration: none; }
a:hover { color: var(--cgh-purple); }
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--cgh-blue);
  outline-offset: 2px;
}

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  min-height: 100vh;
  min-height: 100dvh;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

.sidebar {
  background: linear-gradient(180deg, var(--cgh-blue-deep), #12305f 55%, #1a3f78);
  color: #fff;
  padding: 1.25rem 0.85rem 2rem;
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  z-index: 40;
  min-width: 0;
}
.brand {
  position: relative;
  padding: 0.5rem 0.75rem 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,.12);
  margin-bottom: 1rem;
}
.brand-mark {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: .02em;
}
.brand-sub { font-size: .78rem; opacity: .75; margin-top: .25rem; line-height: 1.35; }
.sidebar-close {
  display: none;
  position: absolute;
  top: .35rem;
  right: .35rem;
  width: var(--tap);
  height: var(--tap);
  border: 0;
  border-radius: 8px;
  background: rgba(255,255,255,.12);
  color: #fff;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.nav-section {
  margin: 1rem 0 .35rem;
  padding: 0 .75rem;
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  opacity: .55;
}
.nav a {
  display: flex;
  align-items: center;
  color: rgba(255,255,255,.88);
  padding: .55rem .75rem;
  border-radius: 8px;
  margin: .15rem 0;
  font-size: .92rem;
  min-height: var(--tap);
}
.nav a:hover, .nav a.active {
  background: rgba(255,255,255,.12);
  color: #fff;
}
.nav a:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}
.nav a.share-link {
  border: 1px solid rgba(201, 179, 239, .45);
  background: rgba(108, 63, 197, .25);
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(12, 28, 54, .45);
  z-index: 35;
  border: 0;
  padding: 0;
  margin: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.sidebar-overlay.is-visible { display: block; }

.nav-toggle {
  display: none;
  flex-shrink: 0;
  width: var(--tap);
  height: var(--tap);
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow);
  cursor: pointer;
  padding: 0;
  color: var(--cgh-blue-deep);
}
.nav-toggle:hover { border-color: var(--cgh-blue); }
.nav-toggle-bars,
.nav-toggle-bars::before,
.nav-toggle-bars::after {
  display: block;
  width: 18px;
  height: 2px;
  background: currentColor;
  border-radius: 1px;
  position: relative;
}
.nav-toggle-bars::before,
.nav-toggle-bars::after {
  content: "";
  position: absolute;
  left: 0;
}
.nav-toggle-bars::before { top: -6px; }
.nav-toggle-bars::after { top: 6px; }

.main {
  padding: 1.25rem 1.5rem 2.5rem;
  min-width: 0;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.25rem;
  min-width: 0;
}
.topbar-left {
  display: flex;
  align-items: center;
  gap: .75rem;
  min-width: 0;
  flex: 1;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: .55rem;
  flex-shrink: 0;
  min-width: 0;
}
.page-title {
  margin: 0;
  font-size: 1.55rem;
  font-family: var(--font-display);
  color: var(--cgh-blue-deep);
  line-height: 1.25;
  overflow-wrap: anywhere;
  min-width: 0;
}
.user-chip {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-shrink: 0;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: .35rem .75rem .35rem .9rem;
  font-size: .88rem;
  box-shadow: var(--shadow);
}
.logout-form { display: inline; margin: 0; }

.flash {
  padding: .85rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  border: 1px solid;
  overflow-wrap: anywhere;
  max-width: 100%;
}
.flash-success { background: #e8f8ef; border-color: #a7e0bf; color: #146c3a; }
.flash-error { background: #fdecea; border-color: #f5c2c0; color: #922b21; }

.grid { display: grid; gap: 1rem; min-width: 0; }
.grid > * { min-width: 0; max-width: 100%; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  box-shadow: var(--shadow);
  min-width: 0;
  max-width: 100%;
}
.card h3 { margin: 0 0 .35rem; font-size: .95rem; color: var(--muted); font-weight: 600; }
.card .value {
  font-size: 1.55rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.card.metric-cash { border-top: 3px solid var(--cgh-blue); }
.card.metric-profit { border-top: 3px solid var(--cgh-purple); }
.card.metric-dist { border-top: 3px solid var(--cgh-orange); }
.card.metric-share {
  background: var(--share-bg);
  border: 1px solid var(--share-border);
  border-top: 3px solid var(--cgh-purple);
}

.section-title {
  font-size: 1.05rem;
  margin: 1.5rem 0 .75rem;
  color: var(--cgh-blue-deep);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .5rem;
  min-width: 0;
  max-width: 100%;
}
.section-title .badge,
.badge {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: .72rem;
  background: var(--cgh-purple);
  color: #fff;
  padding: .15rem .5rem;
  border-radius: 999px;
  line-height: 1.3;
}

.share-panel {
  background: linear-gradient(135deg, #faf6ff, #fff);
  border: 1px dashed var(--share-border);
  border-radius: var(--radius);
  padding: 1.2rem;
  min-width: 0;
  max-width: 100%;
}
.share-panel h2 { margin: 0 0 .5rem; color: var(--cgh-purple); font-size: 1.15rem; }
.share-panel .hint { color: var(--muted); font-size: .88rem; margin-bottom: 1rem; }

.amount-positive { color: var(--positive); }
.amount-negative { color: var(--negative); }
.amount-zero { color: var(--muted); }

/* Contained horizontal scroll — never expands the page */
.table-scroll {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius);
  margin: 0;
  min-width: 0;
}
.table-scroll > table.data {
  margin: 0;
}

table.data {
  width: 100%;
  min-width: 520px;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}
table.data th, table.data td {
  padding: .7rem .85rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-size: .92rem;
  vertical-align: middle;
}
table.data th {
  background: #eef3fa;
  color: var(--muted);
  font-weight: 600;
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  white-space: nowrap;
}
table.data td { overflow-wrap: anywhere; }
table.data tr:last-child td { border-bottom: 0; }

.cell-date,
.cell-amount,
td.cell-date,
td.cell-amount {
  white-space: nowrap !important;
  overflow-wrap: normal !important;
  word-break: normal !important;
}
.cell-amount,
td.cell-amount {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .35rem;
  border: 0;
  border-radius: 8px;
  padding: .55rem .95rem;
  font-weight: 600;
  cursor: pointer;
  font-size: .9rem;
  min-height: var(--tap);
  text-align: center;
  text-decoration: none;
  max-width: 100%;
}
.btn-primary { background: var(--cgh-blue); color: #fff; }
.btn-primary:hover { background: var(--cgh-blue-deep); color: #fff; }
.btn-orange { background: var(--cgh-orange); color: #fff; }
.btn-purple { background: var(--cgh-purple); color: #fff; }
.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-danger { background: var(--negative); color: #fff; }
.btn-sm {
  padding: .35rem .65rem;
  font-size: .8rem;
  min-height: 36px;
}

.form-grid { display: grid; gap: .9rem; max-width: 720px; width: 100%; }
.form-row { display: grid; gap: .35rem; min-width: 0; }
.form-row label { font-size: .85rem; color: var(--muted); font-weight: 600; }
.form-row input,
.form-row select,
.form-row textarea {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .65rem .75rem;
  font: inherit;
  background: #fff;
  width: 100%;
  max-width: 100%;
  min-height: var(--tap);
}
.form-row textarea { min-height: 96px; }
.form-row input:focus,
.form-row select:focus,
.form-row textarea:focus {
  outline: 2px solid rgba(26, 95, 180, .25);
  border-color: var(--cgh-blue);
}
.actions {
  display: flex;
  gap: .6rem;
  flex-wrap: wrap;
  margin-top: .5rem;
  max-width: 100%;
}

/* ---------- Auth / login (premium, light) ---------- */
.auth-body {
  font-family: "Plus Jakarta Sans", var(--font);
  background: #f3f6fb;
}

.login-wrap {
  position: relative;
  isolation: isolate;
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1.5rem 1.15rem max(1.5rem, env(safe-area-inset-bottom));
  max-width: 100%;
  overflow-x: hidden;
  background:
    radial-gradient(900px 520px at 12% -8%, rgba(26, 95, 180, .22), transparent 58%),
    radial-gradient(700px 480px at 100% 8%, rgba(230, 126, 34, .16), transparent 52%),
    radial-gradient(640px 420px at 70% 100%, rgba(108, 63, 197, .14), transparent 55%),
    linear-gradient(165deg, #e8f0fb 0%, #f5f7fc 42%, #eef1f8 100%);
}

.login-atmosphere {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}
.login-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(40px);
  opacity: .55;
  animation: login-float 14s ease-in-out infinite;
}
.login-orb-a {
  width: 220px; height: 220px;
  top: 8%; left: -40px;
  background: rgba(26, 95, 180, .35);
}
.login-orb-b {
  width: 180px; height: 180px;
  top: 55%; right: -30px;
  background: rgba(108, 63, 197, .28);
  animation-delay: -4s;
}
.login-orb-c {
  width: 140px; height: 140px;
  bottom: 12%; left: 35%;
  background: rgba(230, 126, 34, .22);
  animation-delay: -7s;
}
.login-grid {
  position: absolute;
  inset: 0;
  opacity: .35;
  background-image:
    linear-gradient(rgba(13, 59, 122, .05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(13, 59, 122, .05) 1px, transparent 1px);
  background-size: 28px 28px;
  mask-image: radial-gradient(ellipse at center, #000 30%, transparent 75%);
}

@keyframes login-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-18px); }
}

.login-stage {
  position: relative;
  z-index: 1;
  width: min(420px, 100%);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 1.15rem;
  animation: login-rise .55s ease-out both;
}

@keyframes login-rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

.login-hero {
  text-align: center;
  padding: .25rem .5rem 0;
}
.login-logo {
  width: 72px;
  height: 72px;
  margin: 0 auto .9rem;
  border-radius: 20px;
  overflow: hidden;
  box-shadow:
    0 12px 28px rgba(13, 59, 122, .22),
    0 0 0 3px rgba(255, 255, 255, .75);
}
.login-logo img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.login-brand {
  margin: 0;
  font-family: "Plus Jakarta Sans", var(--font-display);
  font-weight: 800;
  font-size: clamp(1.85rem, 6vw, 2.35rem);
  letter-spacing: -.03em;
  line-height: 1.1;
  color: var(--cgh-blue-deep);
  background: linear-gradient(120deg, var(--cgh-blue-deep) 0%, var(--cgh-purple) 70%, #a85a12 140%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.login-tagline {
  margin: .55rem 0 0;
  color: var(--muted);
  font-size: .92rem;
  line-height: 1.45;
  font-weight: 500;
}

.login-card {
  width: 100%;
  background: rgba(255, 255, 255, .88);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-radius: 20px;
  padding: 1.65rem 1.4rem 1.4rem;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, .9) inset,
    0 18px 48px rgba(13, 59, 122, .12);
  border: 1px solid rgba(216, 224, 234, .9);
  max-width: 100%;
}

.login-alert {
  margin-bottom: 1rem;
  border-radius: 12px;
  font-size: .92rem;
  font-weight: 550;
}
.login-form .form-row label {
  font-weight: 600;
  font-size: .86rem;
  color: #334155;
}
.login-form input[type="email"],
.login-form input[type="password"] {
  background: #f7f9fc;
  border: 1px solid #d5dee9;
  border-radius: 12px;
  min-height: 48px;
  padding: .7rem .95rem;
  font-size: 1rem;
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
.login-form input:hover {
  border-color: #b8c7da;
}
.login-form input:focus {
  background: #fff;
  border-color: var(--cgh-blue);
  box-shadow: 0 0 0 3px rgba(26, 95, 180, .18);
  outline: none;
}
/* Reduce ugly autofill clash */
.login-form input:-webkit-autofill,
.login-form input:-webkit-autofill:hover,
.login-form input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--text);
  box-shadow: 0 0 0 1000px #f7f9fc inset;
  transition: background-color 9999s ease-out;
}

.login-submit {
  width: 100%;
  min-height: 48px;
  margin-top: .35rem;
  border-radius: 12px;
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: .01em;
  background: linear-gradient(135deg, var(--cgh-blue) 0%, #2a4fa8 55%, var(--cgh-purple) 130%);
  border: 0;
  box-shadow: 0 10px 22px rgba(26, 95, 180, .28);
}
.login-submit:hover {
  filter: brightness(1.05);
  color: #fff;
}

.login-trust {
  margin: 1.1rem 0 0;
  text-align: center;
  font-size: .78rem;
  line-height: 1.4;
  color: var(--muted);
}

.login-pwa-hint {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .35rem;
  text-align: center;
}
.login-pwa-hint .btn {
  border-radius: 999px;
  background: rgba(255, 255, 255, .7);
  border-color: rgba(26, 95, 180, .25);
}
.login-pwa-hint .muted { font-size: .78rem; }

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  min-width: 0;
  max-width: 100%;
}
.toolbar label {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .4rem;
  font-size: .88rem;
  color: var(--muted);
  font-weight: 600;
}
.toolbar input,
.toolbar select {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .55rem .7rem;
  font: inherit;
  background: #fff;
  min-height: var(--tap);
  max-width: 100%;
}
.muted { color: var(--muted); }

.tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: .2rem .55rem;
  border-radius: 999px;
  font-size: .75rem;
  line-height: 1.3;
  background: #eef3fa;
  color: var(--cgh-blue-deep);
  vertical-align: middle;
}
.tag-share { background: #efe6ff; color: var(--cgh-purple); }
.tag-warn { background: #fff0e0; color: var(--warn); }
.tag-ok { background: #e6f6ec; color: var(--positive); }

/* Dashboard partner balances — card stack (no wide table) */
.partner-balance-list {
  display: grid;
  gap: .75rem;
  min-width: 0;
  max-width: 100%;
}
.partner-balance-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
  min-width: 0;
  max-width: 100%;
}
.partner-balance-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: .75rem;
  margin-bottom: .85rem;
  min-width: 0;
}
.partner-name-block {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: .4rem;
  min-width: 0;
  flex: 1;
}
.partner-name {
  font-size: 1.05rem;
  color: var(--cgh-blue-deep);
  overflow-wrap: anywhere;
}
.partner-balance-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .75rem;
}
.partner-metric-value {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  margin-top: .2rem;
  white-space: nowrap;
}
.partner-type-cell {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: .35rem;
  min-width: 0;
}

/* Stack lists — Son İşlemler / Yaklaşan Vadeler */
.dash-split { align-items: start; }
.dash-panel { min-width: 0; max-width: 100%; }
.stack-list {
  display: grid;
  gap: .65rem;
  min-width: 0;
  max-width: 100%;
}
.stack-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .85rem 1rem;
  box-shadow: var(--shadow);
  min-width: 0;
  max-width: 100%;
}
.stack-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  flex-wrap: wrap;
  min-width: 0;
}
.stack-item-desc {
  margin: .45rem 0 0;
  font-size: .9rem;
  color: var(--text);
  overflow-wrap: anywhere;
  line-height: 1.4;
}
.stack-item-amount {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  margin-top: .35rem;
  text-align: right;
}
.stack-item-top .stack-item-amount { margin-top: 0; }

/* Inline action rows (debts pay, approvals) */
form[style*="display:flex"],
form[style*="display: flex"] {
  flex-wrap: wrap;
  max-width: 100%;
}
form[style*="display:flex"] input,
form[style*="display: flex"] input {
  max-width: 100%;
  min-height: 40px;
}

/* ---------- Tablet / laptop narrow ---------- */
@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 980px) {
  .app-shell { grid-template-columns: minmax(0, 1fr); }

  .nav-toggle { display: inline-flex; }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: min(300px, 86vw);
    height: 100vh;
    height: 100dvh;
    transform: translateX(-105%);
    transition: transform .22s ease;
    box-shadow: none;
    padding-top: max(1.25rem, env(safe-area-inset-top));
    padding-bottom: max(2rem, env(safe-area-inset-bottom));
  }
  .sidebar.is-open {
    transform: translateX(0);
    box-shadow: 8px 0 32px rgba(13, 59, 122, .28);
  }
  .sidebar-close { display: inline-flex; align-items: center; justify-content: center; }

  .main {
    padding: 0 max(.9rem, env(safe-area-inset-right)) max(2rem, env(safe-area-inset-bottom)) max(.9rem, env(safe-area-inset-left));
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    margin: 0 calc(-1 * max(.9rem, env(safe-area-inset-right))) 1rem calc(-1 * max(.9rem, env(safe-area-inset-left)));
    width: auto;
    max-width: none;
    padding: .65rem max(.9rem, env(safe-area-inset-right)) .65rem max(.9rem, env(safe-area-inset-left));
    padding-top: max(.65rem, env(safe-area-inset-top));
    background: rgba(238, 243, 249, .92);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
    min-height: var(--topbar-h);
  }

  .grid-2,
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  .page-title { font-size: 1.25rem; }
  .user-chip { padding: .3rem .55rem .3rem .7rem; }
  .user-chip-name {
    max-width: 7.5rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .topbar-right { gap: .4rem; }
  .notif-panel {
    right: 0;
    left: auto;
    width: min(320px, calc(100vw - 1.5rem));
  }

  .card { padding: 1rem; }
  .card .value { font-size: 1.3rem; }
  .share-panel { padding: 1rem; }

  .form-grid { max-width: 100%; }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }
  .toolbar > .btn,
  .toolbar > a.btn,
  .toolbar > button {
    width: 100%;
  }
  .toolbar label {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }
  .toolbar input,
  .toolbar select { width: 100%; }

  .actions { width: 100%; }
  .actions .btn { flex: 1 1 auto; min-width: calc(50% - .4rem); }

  /* Sticky first column while scrolling tables inside .table-scroll only */
  .table-scroll table.data th:first-child,
  .table-scroll table.data td:first-child {
    position: sticky;
    left: 0;
    z-index: 1;
    background: var(--surface);
    box-shadow: 2px 0 0 var(--border);
  }
  .table-scroll table.data th:first-child {
    background: #eef3fa;
    z-index: 2;
  }
}

/* ---------- Phone ---------- */
@media (max-width: 768px) {
  .dash-split.grid-2,
  .grid.dash-split { grid-template-columns: 1fr; }

  .partner-balance-metrics {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .grid-2,
  .grid-3,
  .grid-4 { grid-template-columns: 1fr; }

  .topbar {
    flex-wrap: wrap;
    align-items: flex-start;
    gap: .65rem;
  }
  .topbar-left { width: 100%; }
  .topbar-right {
    width: 100%;
    justify-content: space-between;
  }
  .user-chip {
    width: auto;
    flex: 1;
    justify-content: space-between;
    border-radius: 12px;
  }
  .user-chip-name { max-width: none; }
  .notif-panel {
    left: 0;
    right: auto;
    width: min(340px, calc(100vw - 1.25rem));
  }

  .page-title { font-size: 1.15rem; }
  .section-title { font-size: 1rem; }

  .btn-sm { min-height: var(--tap); padding: .45rem .75rem; }

  .login-card { padding: 1.35rem 1.1rem 1.2rem; }
  .login-wrap { padding: 1rem; }
  .login-brand { font-size: 1.85rem; }
  .login-logo { width: 64px; height: 64px; border-radius: 16px; }

  table.data { min-width: 440px; }
  table.data th, table.data td {
    padding: .65rem .7rem;
    font-size: .88rem;
  }

  .actions .btn {
    flex: 1 1 100%;
    width: 100%;
  }

  .partner-balance-head {
    flex-wrap: wrap;
  }
  .partner-balance-head .btn {
    width: 100%;
  }
}

@media (max-width: 400px) {
  .main {
    padding-left: max(.7rem, env(safe-area-inset-left));
    padding-right: max(.7rem, env(safe-area-inset-right));
  }
  .topbar {
    margin-left: calc(-1 * max(.7rem, env(safe-area-inset-left)));
    margin-right: calc(-1 * max(.7rem, env(safe-area-inset-right)));
    padding-left: max(.7rem, env(safe-area-inset-left));
    padding-right: max(.7rem, env(safe-area-inset-right));
  }
  .card .value { font-size: 1.2rem; }
  table.data { min-width: 380px; }
}

@media print {
  .sidebar,
  .sidebar-overlay,
  .nav-toggle,
  .sidebar-close,
  .topbar .user-chip,
  .topbar-right,
  .pwa-install-banner,
  .notif-perm-prompt,
  .btn,
  .no-print { display: none !important; }
  .app-shell { display: block; }
  .main { padding: 0; }
  .topbar { position: static; background: none; border: 0; padding: 0; }
  body { background: #fff; overflow: visible; }
  table.data { min-width: 0; }
  .table-scroll { overflow: visible; }
}

/* ---------- Notifications ---------- */
.notif-wrap { position: relative; }
.notif-bell {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--tap);
  height: var(--tap);
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--cgh-blue-deep);
  cursor: pointer;
  box-shadow: var(--shadow);
}
.notif-bell:hover { border-color: var(--cgh-blue); color: var(--cgh-purple); }
.notif-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  min-width: 1.1rem;
  height: 1.1rem;
  padding: 0 .25rem;
  border-radius: 999px;
  background: var(--cgh-orange);
  color: #fff;
  font-size: .68rem;
  font-weight: 700;
  line-height: 1.1rem;
  text-align: center;
  box-shadow: 0 0 0 2px #fff;
}
.notif-panel {
  position: absolute;
  top: calc(100% + .45rem);
  right: 0;
  width: 340px;
  max-width: calc(100vw - 1.5rem);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 16px 40px rgba(13, 59, 122, .16);
  z-index: 80;
  overflow: hidden;
}
.notif-panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .5rem;
  padding: .75rem .9rem;
  border-bottom: 1px solid var(--border);
  background: #f7f9fc;
}
.notif-panel-actions {
  display: flex;
  gap: .65rem;
  align-items: center;
  font-size: .82rem;
}
.notif-panel-actions a,
.linkish {
  background: none;
  border: 0;
  padding: 0;
  color: var(--cgh-blue);
  cursor: pointer;
  font: inherit;
  text-decoration: none;
}
.notif-panel-actions a:hover,
.linkish:hover { color: var(--cgh-purple); }
.notif-panel-list {
  max-height: min(360px, 55vh);
  overflow: auto;
}
.notif-item {
  display: block;
  padding: .75rem .9rem;
  border-bottom: 1px solid var(--border);
  color: inherit;
}
.notif-item:hover { background: #f5f8fc; }
.notif-item.is-unread { background: #f3f7ff; }
.notif-item-title { font-weight: 650; font-size: .9rem; margin-bottom: .2rem; }
.notif-item-body { font-size: .82rem; margin-bottom: .25rem; }
.notif-item-meta { font-size: .75rem; }
.notif-empty { padding: 1.25rem .9rem; text-align: center; font-size: .9rem; }

.notif-list .notif-row {
  display: flex;
  justify-content: space-between;
  gap: .75rem;
  padding: .85rem 0;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.notif-list .notif-row:last-child { border-bottom: 0; }
.notif-row.is-unread .notif-title { font-weight: 700; }
.notif-row-actions { display: flex; gap: .35rem; align-items: flex-start; flex-wrap: wrap; }

.notif-perm-prompt {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .75rem;
  flex-wrap: wrap;
  padding: .85rem 1rem;
  margin-bottom: 1rem;
  border-radius: var(--radius);
  border: 1px solid #c9d7ea;
  background: #eef4fb;
}
.notif-perm-prompt[hidden] { display: none !important; }

.check-row {
  display: flex;
  align-items: flex-start;
  gap: .55rem;
  font-weight: 600;
}
.check-row input { margin-top: .2rem; }

.role-check-grid {
  display: grid;
  gap: .55rem;
}
.perm-module {
  margin: 1rem 0 1.25rem;
  padding-bottom: .75rem;
  border-bottom: 1px solid var(--border);
}
.perm-module:last-of-type { border-bottom: 0; }
.perm-module-title {
  margin: 0 0 .65rem;
  font-size: .95rem;
  color: var(--cgh-blue-deep);
}

/* ---------- PWA install banner ---------- */
.pwa-install-banner {
  position: fixed;
  left: max(.75rem, env(safe-area-inset-left));
  right: max(.75rem, env(safe-area-inset-right));
  bottom: max(.75rem, env(safe-area-inset-bottom));
  z-index: 120;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .75rem;
  flex-wrap: wrap;
  padding: .85rem 1rem;
  border-radius: 14px;
  background: rgba(255, 255, 255, .96);
  border: 1px solid var(--border);
  box-shadow: 0 14px 36px rgba(13, 59, 122, .18);
  animation: login-rise .35s ease-out both;
}
.pwa-install-text {
  display: flex;
  flex-direction: column;
  gap: .15rem;
  min-width: 0;
  font-size: .88rem;
}
.pwa-install-text strong { color: var(--cgh-blue-deep); }
.pwa-install-text span { color: var(--muted); font-size: .82rem; }
.pwa-install-actions { display: flex; gap: .4rem; flex-wrap: wrap; }

/* ---------- Expense documents ---------- */
.doc-panel { margin-top: 1rem; }
.doc-panel h3 { margin: 0 0 .75rem; }
.doc-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: .85rem;
  margin-bottom: 1rem;
}
.doc-card {
  display: flex;
  flex-direction: column;
  gap: .5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fbfdff;
  overflow: hidden;
  min-width: 0;
}
.doc-thumb {
  display: block;
  aspect-ratio: 4 / 3;
  background: #e8eef6;
  overflow: hidden;
}
.doc-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.doc-thumb--file {
  display: grid;
  place-items: center;
  font-weight: 700;
  color: var(--cgh-blue-deep);
  letter-spacing: .04em;
}
.doc-meta {
  display: flex;
  flex-direction: column;
  gap: .35rem;
  padding: 0 .7rem .7rem;
  min-width: 0;
}
.doc-name {
  font-size: .86rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.doc-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
}
.doc-upload-row input[type="file"] {
  width: 100%;
  max-width: 100%;
  padding: .65rem .7rem;
  border: 1px dashed var(--border);
  border-radius: 10px;
  background: #fff;
  font-size: 1rem;
  min-height: var(--tap);
}
.doc-upload-form { margin-top: 1rem; padding-top: .5rem; border-top: 1px solid var(--border); }
.form-hint { margin: .35rem 0 0; font-size: .8rem; }
@media (max-width: 640px) {
  .doc-gallery { grid-template-columns: 1fr 1fr; gap: .65rem; }
  .doc-upload-row input[type="file"] { font-size: 16px; }
}
