@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&family=Inter:wght@400;500;600;700&family=Roboto+Mono:wght@500&display=swap');

/*
  Palette sampled directly from the Finbill app icon/logo:
  navy bg gradient ~ #00132F -> #0B1F49, bright accent blue ~ #0379FD,
  icon gradient blue ~ #0066FD -> #39A0FF, wordmark ink ~ #00143E.
*/
:root {
  --bg: #F5F7FB;
  --surface: #ffffff;
  --ink: #0A1B3D;
  --muted: #5C6B85;
  --faint: #9AA6BC;
  --border: #E3E8F2;

  --navy-950: #030B1F;
  --navy-900: #071633;
  --navy-800: #0C2050;

  --accent: #0B6EFD;
  --accent-2: #39A0FF;
  --accent-ink: #ffffff;
  --accent-soft: #E8F1FF;
  --accent-soft-ink: #0B5FDA;
  --accent-gradient: linear-gradient(135deg, #0066FD 0%, #39A0FF 100%);

  --danger: #D0281B;
  --danger-soft: #FCEBEA;
  --warn: #9A6700;
  --warn-soft: #FBF3E0;
  --success: #12825A;
  --success-soft: #E3F6EE;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(7, 22, 51, 0.05), 0 10px 28px -14px rgba(7, 22, 51, 0.18);
  --shadow-lg: 0 20px 60px -20px rgba(3, 11, 31, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, .brand, .num {
  font-family: 'Space Grotesk', 'Inter', sans-serif;
}

code, .mono, .ledger-id {
  font-family: 'Roboto Mono', monospace;
  font-size: 0.85em;
}

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

img { max-width: 100%; display: block; }

/* ---------- Layout shell ---------- */

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 250px;
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--navy-900) 0%, var(--navy-950) 100%);
  color: #C9D3E8;
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-topbar { display: none; }

.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 17px;
  padding: 6px 8px 22px;
  color: #ffffff;
}

.brand .mark {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  flex-shrink: 0;
  overflow: hidden;
}
.brand .mark img { width: 100%; height: 100%; object-fit: contain; }

.sidebar nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar nav a {
  color: #A9B6D1;
  text-decoration: none;
  padding: 10px 12px;
  border-radius: 8px;
  font-weight: 500;
  font-size: 13.5px;
  transition: background 0.12s ease, color 0.12s ease;
}

.sidebar nav a:hover { background: rgba(255,255,255,0.06); color: #ffffff; }
.sidebar nav a.active {
  background: var(--accent-gradient);
  color: #ffffff;
  box-shadow: 0 6px 16px -6px rgba(11, 110, 253, 0.55);
}

.sidebar .spacer { flex: 1; }

.sidebar .who {
  border-top: 1px solid rgba(255,255,255,0.08);
  padding-top: 14px;
  font-size: 12.5px;
  color: #7C8AA8;
}

.sidebar .who strong { display: block; color: #fff; font-size: 13px; }

.main {
  flex: 1;
  min-width: 0;
  padding: 32px 40px 60px;
}

.topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
  flex-wrap: wrap;
}

.topline h1 { font-size: clamp(19px, 2.4vw, 23px); margin: 0; font-weight: 600; }
.topline .sub { color: var(--muted); font-size: 13px; margin-top: 4px; }

.breadcrumb { color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.breadcrumb a { color: var(--muted); }

/* ---------- Auth screen ---------- */

.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 18% 15%, rgba(11,110,253,0.16), transparent 42%),
    radial-gradient(circle at 85% 85%, rgba(57,160,255,0.12), transparent 45%),
    var(--navy-950);
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  padding: 38px 32px 32px;
}

.auth-card .logo-lockup { display: block; margin: 0 auto 22px; max-width: 220px; }
.auth-card .tagline { text-align: center; color: var(--muted); font-size: 13px; margin: 0 0 28px; }

/* ---------- Cards / grid ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}

.grid-cols {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 16px;
}

.company-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: box-shadow 0.15s ease, transform 0.15s ease, border-color 0.15s ease;
}

.company-card:hover { box-shadow: var(--shadow); transform: translateY(-2px); border-color: #CFE0FF; }

.company-card .swatch {
  width: 36px; height: 36px; border-radius: 9px; flex-shrink: 0;
  border: 1px solid rgba(0,0,0,0.06);
  box-shadow: inset 0 0 0 3px rgba(255,255,255,0.35);
}

.company-card .row1 { display: flex; align-items: center; gap: 12px; }
.company-card .name { font-weight: 600; font-size: 15.5px; }
.company-card .code { color: var(--faint); font-size: 12px; }
.company-card .meta { display: flex; gap: 14px; color: var(--muted); font-size: 12.5px; margin-top: 2px; flex-wrap: wrap; }

/* ---------- Forms ---------- */

label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  margin: 14px 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

label:first-child { margin-top: 0; }

label .opt { text-transform: none; font-weight: 400; color: var(--faint); }

input[type=text], input[type=email], input[type=password], input[type=number], textarea, select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
  font-family: inherit;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

textarea { resize: vertical; min-height: 70px; }

.help { font-size: 12px; color: var(--faint); margin-top: 5px; }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.field-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

.checkbox-row {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 0;
}
.checkbox-row input { width: auto; accent-color: var(--accent); }
.checkbox-row label { margin: 0; text-transform: none; font-weight: 500; color: var(--ink); font-size: 13.5px; }

.color-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.color-row input[type=color] {
  width: 46px; height: 38px; padding: 2px; border-radius: 8px; border: 1px solid var(--border); cursor: pointer;
}
.color-swatches { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.swatch-btn {
  width: 26px; height: 26px; border-radius: 6px; border: 1px solid rgba(0,0,0,0.08); cursor: pointer;
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  font-family: inherit;
  transition: filter 0.12s ease, background 0.12s ease, border-color 0.12s ease, opacity 0.12s ease, transform 0.08s ease;
}

.btn-primary { background: var(--accent-gradient); color: var(--accent-ink); box-shadow: 0 6px 16px -8px rgba(11,110,253,0.6); }
.btn-primary:hover { filter: brightness(1.06); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: 0.55; cursor: default; filter: none; box-shadow: none; }

.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg); }

.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-danger:hover { background: #f7d7d4; }

.btn-ghost { background: transparent; color: var(--muted); border-color: transparent; padding: 6px 10px; }
.btn-ghost:hover { background: var(--bg); color: var(--ink); }

.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn-block { width: 100%; }

/* ---------- Tabs ---------- */

.tabbar {
  display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 22px;
  overflow-x: auto;
}
.tabbar button {
  background: none; border: none; padding: 10px 14px; font-family: inherit;
  font-size: 13.5px; font-weight: 600; color: var(--muted); cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap;
}
.tabbar button.active { color: var(--accent); border-bottom-color: var(--accent); }
.tabbar button:hover { color: var(--ink); }

.tabpanel { display: none; }
.tabpanel.active { display: block; }

/* ---------- Table ---------- */

.table-scroll { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 560px; }
th, td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--border); font-size: 13.5px; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.02em; }
tr:last-child td { border-bottom: none; }
td.actions { text-align: right; white-space: nowrap; }

.pill {
  display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600;
  text-transform: capitalize;
}
.pill-developer { background: #F0E7FC; color: #6B3FB0; }
.pill-admin { background: var(--accent-soft); color: var(--accent-soft-ink); }
.pill-partner { background: #E3ECFB; color: #2453A6; }
.pill-biller { background: #EEF0F5; color: #5C6B85; }

.pill-active { background: var(--success-soft); color: var(--success); }
.pill-inactive { background: var(--danger-soft); color: var(--danger); }

/* ---------- Misc ---------- */

.empty-state {
  text-align: center; padding: 60px 20px; color: var(--muted);
}
.empty-state h3 { color: var(--ink); margin-bottom: 6px; }

.toast {
  position: fixed; bottom: 24px; right: 24px; left: 24px; z-index: 60;
  margin-left: auto;
  background: var(--navy-900); color: #fff; padding: 12px 18px; border-radius: 8px;
  font-size: 13.5px; box-shadow: var(--shadow-lg); max-width: 340px;
}
.toast.error { background: var(--danger); }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(3, 11, 31, 0.55); z-index: 50;
  display: flex; align-items: flex-start; justify-content: center; padding: 40px 20px; overflow-y: auto;
}
.modal {
  background: var(--surface); border-radius: 14px; width: 100%; max-width: 520px;
  padding: 26px 26px 22px; box-shadow: var(--shadow-lg);
  max-height: calc(100vh - 60px);
  overflow-y: auto;
}
.modal h2 { margin: 0 0 4px; font-size: 18px; }
.modal .modal-sub { color: var(--muted); font-size: 13px; margin: 0 0 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; flex-wrap: wrap; }

.error-box {
  background: var(--danger-soft); color: var(--danger); border-radius: 8px; padding: 10px 12px;
  font-size: 13px; margin-top: 14px;
}

.section-title {
  font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em;
  color: var(--muted); margin: 26px 0 12px;
}
.section-title:first-child { margin-top: 0; }

.loading { color: var(--faint); padding: 30px; text-align: center; font-size: 13.5px; }

.tab-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 4px 20px;
}

/* ---------- Responsive breakpoints ---------- */

/* Tablet: tighten spacing, ease field-row-3 down to 2 columns */
@media (max-width: 1024px) {
  .main { padding: 26px 24px 50px; }
  .field-row-3 { grid-template-columns: 1fr 1fr; }
}

/* Below this width the fixed sidebar becomes a collapsible top bar */
@media (max-width: 900px) {
  .app-shell { flex-direction: column; }

  .sidebar {
    position: sticky; top: 0; z-index: 40;
    width: 100%; height: auto; padding: 0;
    flex-direction: column;
  }

  .sidebar-topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 16px;
  }
  .sidebar-topbar .brand { padding: 0; }

  .nav-toggle {
    background: rgba(255,255,255,0.08); border: none; color: #fff;
    width: 36px; height: 36px; border-radius: 8px; cursor: pointer;
    display: flex; align-items: center; justify-content: center; font-size: 18px;
    flex-shrink: 0;
  }
  .nav-toggle:hover { background: rgba(255,255,255,0.14); }

  .sidebar-collapsible {
    display: none;
    flex-direction: column;
    padding: 0 14px 16px;
    gap: 4px;
  }
  .sidebar-collapsible.open { display: flex; }

  .sidebar nav { flex-direction: column; }
  .sidebar .spacer { display: none; }
  .sidebar .who { border-top: 1px solid rgba(255,255,255,0.08); margin-top: 10px; padding-top: 12px; }

  .main { padding: 22px 18px 50px; }
}

@media (max-width: 640px) {
  html, body { font-size: 14px; }
  .card, .modal { padding: 18px; }
  .field-row, .field-row-3, .tab-grid { grid-template-columns: 1fr; }
  .modal-backdrop { padding: 0; align-items: stretch; }
  .modal { max-width: none; width: 100%; min-height: 100%; border-radius: 0; max-height: none; }
  .grid-cols { grid-template-columns: 1fr; }
  .toast { left: 16px; right: 16px; bottom: 16px; max-width: none; }
  .topline { align-items: flex-start; }
  .topline .btn { width: 100%; }
}
