:root {
  color-scheme: light;
  --navy: #163b65;
  --ink: #1b2b40;
  --muted: #64758b;
  --line: #dbe3ec;
  --bg: #f3f6fb;
  --gold: #f3c94f;
}

* { box-sizing: border-box; }
html { min-width: 320px; width: 100%; overflow-x: hidden; overflow-x: clip; }
body {
  width: 100%; min-width: 320px; max-width: 100%; margin: 0;
  overflow-x: hidden; overflow-x: clip; background: var(--bg); color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
img, svg, video, canvas { max-width: 100%; }
a, button, input, select, textarea { touch-action: manipulation; }

.top {
  width: 100%; min-height: 68px; display: flex; align-items: center;
  justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 12px clamp(14px, 3vw, 34px); background: #fff;
  border-bottom: 1px solid var(--line);
}
.logo { min-width: 0; display: inline-flex; align-items: center; gap: 10px; font-size: 20px; font-weight: 850; color: var(--navy); text-decoration: none; line-height: 1.1; }
.logo img { width: 42px; height: 42px; flex: 0 0 42px; object-fit: contain; }
.brand-label { display: flex; flex-direction: column; color: var(--navy); }
.brand-label small { margin-top: 3px; color: #8a6a10; font-size: 12px; font-weight: 700; letter-spacing: .04em; }
.setup-brand { margin-bottom: 18px; }
.auth .logo { margin-bottom: 12px; }
.user { min-width: 0; font-size: 13px; color: var(--muted); display: flex; gap: 12px; align-items: center; }
.user a { color: var(--navy); white-space: nowrap; }
.env-switch { min-width: 0; display: flex; align-items: center; gap: 5px; padding: 4px; border: 1px solid var(--line); border-radius: 12px; background: #f7f9fc; }
.env-label { padding: 0 5px; color: var(--muted); font-size: 11px; font-weight: 750; }
.env-option { display: inline-flex; align-items: center; gap: 5px; padding: 7px 10px; border: 0; border-radius: 8px; background: transparent; color: #53667c; font-size: 12px; font-weight: 750; }
.env-option .ui-icon { width: 15px; height: 15px; flex-basis: 15px; }
.env-option.active { background: #fff; color: var(--navy); box-shadow: 0 1px 5px #16375618; }
.env-option.live-active { color: #16724a; }
.mode-status { padding: 0 5px; color: var(--muted); font-size: 10px; white-space: nowrap; }
.mode-warning { margin: 0 0 14px; }
.mode-sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.shell {
  width: min(100%, 1600px); min-width: 0; margin: 0 auto;
  padding: clamp(12px, 2vw, 24px); display: grid;
  grid-template-columns: 230px minmax(0, 1fr); gap: clamp(14px, 2vw, 22px);
  align-items: start;
}
.side {
  min-width: 0; position: sticky; top: 16px; background: #fff;
  border: 1px solid var(--line); border-radius: 16px; padding: 10px;
  display: grid; gap: 5px;
}
.side a { display: flex; align-items: center; gap: 9px; min-width: 0; padding: 11px 12px; border-radius: 9px; text-decoration: none; color: #31465f; font-weight: 650; overflow-wrap: anywhere; }
.ui-icon { width: 19px; height: 19px; flex: 0 0 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav-icon { width: 17px; height: 17px; flex-basis: 17px; }
.section-title { display: flex; align-items: center; gap: 9px; }
.section-title .ui-icon { color: var(--navy); }
.button .ui-icon, button .ui-icon { margin-right: 8px; }
.metric-head { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.metric-head .ui-icon { color: var(--navy); }
.side a:hover, .side a:focus-visible { background: #edf3fa; color: var(--navy); outline: 2px solid #87b9ed; }
.side .external { color: #735b16; }
.shell main { width: 100%; min-width: 0; }
h1 { font-size: clamp(25px, 3vw, 36px); margin: 3px 0 16px; letter-spacing: -.025em; overflow-wrap: anywhere; }
h2 { font-size: 20px; margin: 0 0 12px; }
p { overflow-wrap: anywhere; }
.muted { color: var(--muted); }
.panel, .card { min-width: 0; background: #fff; border: 1px solid var(--line); border-radius: 15px; padding: 18px; box-shadow: 0 4px 14px #1329430a; }
.grid { min-width: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr)); gap: 13px; }
.cards { min-width: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.metric small { color: var(--muted); }
.metric strong { display: block; font-size: 26px; margin-top: 5px; overflow-wrap: anywhere; }
.stack { min-width: 0; display: grid; gap: 14px; }
.fields { min-width: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.field { min-width: 0; }
.full { grid-column: 1 / -1; }
label { display: block; color: #43566d; font-weight: 650; font-size: 13px; margin: 0 0 5px; }
input, select, textarea, button { max-width: 100%; font: inherit; }
input, select, textarea { width: 100%; min-width: 0; padding: 10px 12px; border: 1px solid #c6d1df; border-radius: 9px; background: #fff; color: var(--ink); }
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 3px solid #8ac8ff; outline-offset: 2px; }
.actions { min-width: 0; display: flex; gap: 9px; flex-wrap: wrap; margin-top: 14px; }
button, .button { max-width: 100%; display: inline-flex; align-items: center; justify-content: center; padding: 10px 15px; border: 1px solid #224f80; border-radius: 9px; background: var(--navy); color: #fff; font-weight: 700; cursor: pointer; text-decoration: none; text-align: center; }
.button.secondary, button.secondary { background: #fff; color: var(--navy); }
.notice { padding: 12px 14px; background: #fff8df; border: 1px solid #e9d279; border-radius: 10px; color: #654e0d; }
.success { padding: 10px 13px; background: #eaf8ef; color: #17643a; border-radius: 9px; overflow-wrap: anywhere; }
.error { padding: 10px 13px; background: #fff0ed; color: #8c3126; border-radius: 9px; overflow-wrap: anywhere; }
.scroll { width: 100%; max-width: 100%; min-width: 0; overflow: auto; overscroll-behavior-inline: contain; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px; border-bottom: 1px solid #e6ebf1; text-align: left; vertical-align: top; overflow-wrap: anywhere; }
th { font-size: 12px; text-transform: uppercase; color: var(--muted); }
.pill { display: inline-block; padding: 3px 8px; border-radius: 99px; background: #eaf1f8; color: #244b72; font-size: 12px; font-weight: 700; }
.total { text-align: right; font-size: 17px; font-weight: 800; }
.empty { padding: 20px; text-align: center; color: var(--muted); border: 1px dashed #c7d3e1; border-radius: 10px; }
.auth { width: min(100%, 536px); min-width: 0; margin: clamp(20px, 6vh, 64px) auto; padding: 18px; }
.auth .panel { padding: clamp(16px, 4vw, 26px); }
.auth form { display: grid; gap: 12px; }
footer { width: min(100%, 1600px); margin: 10px auto; padding: 10px 20px 24px; text-align: center; color: #77869a; font-size: 12px; }

/* Laptop / narrow desktop */
@media (max-width: 1200px) {
  .shell { grid-template-columns: 210px minmax(0, 1fr); }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Tablet: retain the compact left navigation beside the main content. */
@media (max-width: 900px) {
  .shell { grid-template-columns: clamp(112px, 24vw, 180px) minmax(0, 1fr); padding: 12px; gap: 12px; }
  .side { position: sticky; top: 10px; display: grid; grid-template-columns: minmax(0, 1fr); max-height: calc(100vh - 20px); overflow-y: auto; }
  .side a { min-width: 0; text-align: left; padding: 9px 8px; border: 1px solid #e1e8f0; font-size: 12px; line-height: 1.35; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Mobile */
@media (max-width: 640px) {
  .top { align-items: center; gap: 7px 10px; padding: 10px 12px; }
  .logo { font-size: 18px; gap: 8px; }
  .logo img { width: 38px; height: 38px; flex-basis: 38px; }
  .brand-label small { font-size: 11px; }
  .env-switch { order: 2; flex: 1 1 100%; justify-content: center; }
  .user { order: 3; width: 100%; justify-content: space-between; font-size: 12px; }
  .mode-status { margin-left: auto; }
  .shell { width: 100%; grid-template-columns: clamp(82px, 23vw, 138px) minmax(0, 1fr); padding: 9px; gap: 8px; }
  .side { position: sticky; top: 8px; grid-template-columns: minmax(0, 1fr); gap: 5px; max-height: calc(100vh - 16px); overflow-y: auto; padding: 6px; border-radius: 12px; }
  .side a { font-size: 11px; line-height: 1.3; text-align: left; padding: 8px 5px; }
  h1 { font-size: clamp(23px, 7vw, 30px); margin-bottom: 12px; }
  h2 { font-size: 18px; }
  .panel, .card { padding: 14px; border-radius: 14px; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .metric strong { font-size: clamp(19px, 6vw, 24px); }
  .grid, .fields { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .full { grid-column: auto; }
  .actions { display: grid; grid-template-columns: minmax(0, 1fr); }
  .actions > *, .auth button, .auth .button { width: 100%; }
  .scroll table { min-width: 620px; }
  th, td { padding: 9px 8px; }
  .auth { width: 100%; margin: 18px auto; padding: 12px; }
  footer { padding: 8px 14px 20px; }
}

@media (max-width: 380px) {
  .shell { padding: 7px; gap: 6px; grid-template-columns: 78px minmax(0, 1fr); }
  .side { gap: 4px; padding: 5px; }
  .side a { font-size: 10px; padding: 7px 4px; }
  .panel, .card { padding: 12px; }
  .cards { gap: 7px; }
}

.auth-create { margin: 18px 0 0; display:flex; align-items:center; gap:6px; flex-wrap:wrap; }
.auth-create a { display:inline-flex; align-items:center; gap:6px; color:var(--navy); font-weight:750; text-decoration:none; }
.auth-create a:hover { text-decoration:underline; }
.auth-create .ui-icon { width:19px; height:19px; }
.auth-note { margin: 14px 0 0; font-size: .92rem; }
.hp-field { position:absolute; left:-10000px; width:1px; height:1px; overflow:hidden; }

/* Keep form actions readable at every viewport width. */
.actions { align-items: center; }
.actions > button, .actions > .button {
  flex: 0 1 auto;
  min-width: min(100%, 12rem);
  min-height: 44px;
  white-space: normal;
  overflow-wrap: normal;
  word-break: normal;
  line-height: 1.25;
}
.actions > .save-company-settings { min-width: min(100%, 17rem); }
.invoice-actions > button { min-width: min(100%, 9.5rem); }
.invoice-actions > #issue-invoice { min-width: min(100%, 12rem); }
@media (max-width: 640px) {
  .actions > button, .actions > .button {
    width: 100%; min-width: 0; max-width: 100%;
  }
}

/* FBR company-scoped API configuration */
.fbr-api-status { display:flex; align-items:center; justify-content:space-between; gap:18px; margin:14px 0; border-left:4px solid var(--gold); }
.fbr-api-status > div { display:flex; align-items:flex-start; gap:13px; min-width:0; }
.fbr-api-mark { width:42px; height:42px; flex:0 0 42px; display:grid; place-items:center; border-radius:12px; color:var(--navy); background:#edf3fa; }
.fbr-api-status small { color:#8a6a10; font-weight:800; letter-spacing:.08em; }
.fbr-api-status h2 { margin:3px 0 4px; }
.fbr-api-status p { margin:0; color:var(--muted); }
.fbr-company-identity { display:flex; flex-direction:column; justify-content:center; }
.fbr-company-identity span { color:var(--muted); font-size:14px; }
.fbr-nature { display:grid; grid-template-columns:repeat(auto-fit,minmax(150px,1fr)); gap:8px; }
.fbr-nature label,.fbr-check { display:flex; align-items:center; gap:8px; width:fit-content; margin:3px 0; font-weight:600; }
.fbr-nature input[type=checkbox],.fbr-check input[type=checkbox] { width:18px; height:18px; min-width:18px; margin:0; accent-color:var(--navy); }
.fbr-api-form .panel { scroll-margin-top:20px; }
.fbr-api-endpoints { margin-top:14px; overflow-wrap:anywhere; }
.fbr-api-endpoints code { white-space:normal; overflow-wrap:anywhere; color:#294e71; }
@media(max-width:640px) {
 .fbr-api-status { align-items:stretch; flex-direction:column; }
 .fbr-api-status > .button { width:100%; }
 .fbr-company-picker { grid-template-columns:minmax(0,1fr); }
 .fbr-nature { grid-template-columns:repeat(2,minmax(0,1fr)); }
}
.fbr-add-company { margin: 0 0 14px; }
