:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --border: #e3e7f0;
  --text: #1a1d29;
  --muted: #6b7080;
  --muted-light: #9498a8;
  --accent: #2f6fed;
  --accent-dark: #2158c9;
  --accent-light: #e9f0ff;
  --green: #17a561;
  --green-light: #e5f8ed;
  --orange: #d98b12;
  --orange-light: #fdf1dc;
  --red: #e0392f;
  --red-light: #fdeceb;
  --grey-light: #eef0f4;
  --sidebar-bg: #0d1526;
  --sidebar-fg: #a4acc4;
  --sidebar-active-bg: #2f6fed;
  --sidebar-active-fg: #ffffff;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06);
}

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

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

/* ---- Sidebar ---- */
.sidebar { width: 232px; background: var(--sidebar-bg); color: var(--sidebar-fg); flex-shrink: 0; padding: 20px 12px; display: flex; flex-direction: column; }
.brand { font-weight: 700; color: #fff; padding: 0 12px 24px; font-size: 15px; letter-spacing: -0.01em; display: flex; align-items: center; gap: 9px; }
.brand i { color: var(--accent); font-size: 15px; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.nav-link { color: var(--sidebar-fg); text-decoration: none; padding: 10px 12px; font-size: 13.5px; font-weight: 500; border-radius: var(--radius-sm); transition: background 0.12s, color 0.12s; display: flex; align-items: center; gap: 10px; }
.nav-link i { width: 16px; text-align: center; font-size: 13px; opacity: 0.85; }
.nav-link:hover { background: rgba(255,255,255,0.08); color: #fff; }
.nav-link-active { background: var(--sidebar-active-bg); color: var(--sidebar-active-fg); }
.nav-link-active i { opacity: 1; }
.nav-link-active:hover { background: var(--sidebar-active-bg); }
.nav-link.disabled { opacity: 0.35; cursor: default; }
.nav-link.disabled:hover { background: none; color: var(--sidebar-fg); }

/* ---- Main / topbar ---- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 16px; padding: 14px 28px; border-bottom: 1px solid var(--border); background: var(--surface); }
.topbar .spacer { flex: 1; }
.company-pill { background: var(--accent-light); color: var(--accent-dark); padding: 6px 14px; border-radius: 20px; font-size: 12.5px; font-weight: 600; }
.topbar-link { font-size: 13px; color: var(--muted); text-decoration: none; }
.topbar-link:hover { color: var(--text); }
.as-link { background: none; border: none; cursor: pointer; font: inherit; padding: 0; }
.inline-form { display: inline; }

.content { padding: 28px 32px 48px; max-width: 1180px; }
.content-plain { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(160deg, #f6f7fb 0%, #e9f0ff 100%); }

h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -0.01em; font-weight: 700; }
h2 { font-size: 14.5px; margin: 0 0 14px; font-weight: 600; }
.page-subtitle { color: var(--muted); font-size: 13px; margin-bottom: 22px; }
.back-link { font-size: 13px; color: var(--muted); text-decoration: none; display: inline-block; margin-bottom: 4px; }
.back-link:hover { color: var(--accent); }

/* ---- Cards / grid ---- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px 22px; margin-bottom: 18px; box-shadow: var(--shadow); }
.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); position: relative; overflow: hidden; }
.stat-card::before { content: ""; position: absolute; top: 0; left: 0; width: 4px; height: 100%; background: var(--accent); }
.stat-card .stat-value { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; }
.stat-card .stat-label { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.stat-card-icon { width: 38px; height: 38px; border-radius: 10px; background: var(--accent-light); color: var(--accent-dark); display: flex; align-items: center; justify-content: center; font-size: 15px; margin-bottom: 12px; }
.stat-card-icon-green { background: var(--green-light); color: var(--green); }
.stat-card-icon-red { background: var(--red-light); color: var(--red); }
.stat-section-title { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted-light); margin: 26px 0 12px; display: flex; align-items: center; gap: 6px; }
.stat-section-title:first-child { margin-top: 0; }

/* ---- Tables ---- */
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
    border: 1px solid var(--border);
}

th {
    text-align: left;
    color: var(--muted);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding: 10px 12px;
    vertical-align: middle;
    border: 1px solid var(--border);
}

td {
    padding: 12px;
    vertical-align: middle;
    border: 1px solid var(--border);
}

tbody tr:last-child td {
    border-bottom: 1px solid var(--border);
}
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafbfe; }
.row-num { color: var(--muted-light); width: 32px; }

/* ---- Table card: title + action button + table, one bordered box (matches the Business Hub reference) ---- */
.table-card { border: 1.5px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow: hidden; box-shadow: var(--shadow); margin-bottom: 18px; }
.table-card-header { display: flex; justify-content: space-between; align-items: center; padding: 20px 26px; flex-wrap: wrap; gap: 12px; }
.table-card-header h1 { margin: 0; }
.table-card table th, .table-card table td {
    padding: 10px 10px;
    vertical-align: middle;
}
.table-card table { margin: 0; }

/* ---- Icon action buttons (row-level edit/view) ---- */
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); text-decoration: none; transition: all 0.12s; }
.icon-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-light); }
.icon-btn + .icon-btn { margin-left: 6px; }

/* ---- Badges ---- */
.badge { display: inline-block; font-size: 11px; padding: 4px 10px; border-radius: 20px; font-weight: 600; letter-spacing: 0.01em; }
.badge-green { background: var(--green-light); color: var(--green); }
.badge-red { background: var(--red-light); color: var(--red); }
.badge-grey { background: var(--grey-light); color: var(--muted); }
.badge-orange { background: var(--accent-light); color: var(--accent-dark); }
.badge-blue { background: #e6f0fd; color: #2f6fed; }
.badge-pending { background: var(--orange-light); color: var(--orange); }
.badge i { margin-right: 3px; }
.badge-row { display: flex; gap: 6px; margin-top: 6px; }

/* ---- Buttons ---- */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 9px 18px; border-radius: var(--radius-sm); font-size: 13px; font-weight: 600; border: none; cursor: pointer; text-decoration: none; transition: background 0.12s, box-shadow 0.12s, transform 0.05s; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 1px 2px rgba(79,70,229,0.3); }
.btn-primary:hover { background: var(--accent-dark); }
.btn-primary:disabled { background: var(--grey-light); color: var(--muted-light); cursor: default; box-shadow: none; }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.btn-ghost { background: var(--accent-light); color: var(--accent-dark); border: none; }
.btn-ghost:hover { background: #e0e2fc; }
.btn-danger { background: var(--surface); color: var(--red); border: 1px solid var(--red-light); }
.btn-danger:hover { background: var(--red-light); }
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 14.5px; box-shadow: 0 2px 6px rgba(47, 111, 237, 0.25); }

/* ---- Field rows (label/value pairs) ---- */
.field-row { display: flex; justify-content: space-between; padding: 7px 0; font-size: 13.5px; border-bottom: 1px dashed var(--border); gap: 12px; }
.field-row:last-child { border-bottom: none; }
.field-label { color: var(--muted); }
.field-value { font-weight: 500; text-align: right; }
.muted-small { color: var(--muted-light); font-size: 11.5px; margin-top: 2px; }

/* ---- Forms ---- */
.form-field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.form-field label { font-size: 12px; color: var(--muted); font-weight: 500; }
.form-field input, .form-field select { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 9px 11px; font-size: 13.5px; font-family: inherit; }
.form-field input:focus, .form-field select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }
.form-field.missing input { border-color: var(--red); background: var(--red-light); }

/* ---- Login / select company ---- */
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 36px; width: 380px; box-shadow: 0 8px 24px rgba(16,24,40,0.08); }
.login-card h1 { margin-bottom: 6px; }
.error-text { color: var(--red); font-size: 13px; margin: 10px 0 0; }

.company-list { display: flex; flex-direction: column; gap: 10px; width: 380px; }
.company-option { display: flex; justify-content: space-between; align-items: center; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 15px 18px; text-decoration: none; color: var(--text); font-weight: 500; transition: border-color 0.12s, box-shadow 0.12s; }
.company-option:hover { border-color: var(--accent); box-shadow: var(--shadow); }

.missing-fields-note { font-size: 12px; color: var(--red); margin-top: 8px; }

/* ---- Alerts ---- */
.alert { border-radius: var(--radius); padding: 14px 18px; font-size: 13.5px; margin-bottom: 18px; }
.alert-success { background: var(--green-light); color: #0d7a44; border: 1px solid #bfe9d1; }
.alert-error { background: var(--red-light); color: #b6291f; border: 1px solid #f6c9c5; }

/* ---- Invoice toolbar ---- */
.invoice-toolbar { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin: 8px 0 20px; }
.invoice-toolbar-title { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
.invoice-toolbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---- XML preview ---- */
.xml-preview-card { background: #0f1117; border-color: #0f1117; }
.xml-preview-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.xml-preview-header h2 { color: #d7d9e6; }
.xml-preview-box {
  width: 100%; min-height: 320px; background: #0f1117; color: #b7f0c7; border: none;
  font-family: "SF Mono", Consolas, "Cascadia Code", monospace; font-size: 12px; line-height: 1.6;
  resize: vertical; white-space: pre;
}

/* ---- Invoice document layout ---- */
.invoice-document { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 36px 40px; box-shadow: var(--shadow); }
.invoice-document-header { display: flex; justify-content: space-between; align-items: flex-start; padding-bottom: 24px; border-bottom: 2px solid var(--text); margin-bottom: 28px; }
.invoice-doc-label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 600; }
.invoice-doc-number { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; margin-top: 2px; }
.invoice-doc-meta { min-width: 220px; }
.invoice-doc-meta .field-row { font-size: 13px; }

.invoice-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 32px; margin-bottom: 32px; }
.invoice-party-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted-light); font-weight: 600; margin-bottom: 6px; }
.invoice-party-name { font-size: 15px; font-weight: 700; margin-bottom: 4px; }
.invoice-party > div { font-size: 13px; color: var(--muted); margin-top: 1px; }

.invoice-lines-table th { background: #fafbfe; }
.invoice-lines-table { margin-bottom: 4px; }
.invoice-lines-editable td { vertical-align: middle; }
.line-edit-input { width: 100%; min-width: 90px; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 7px 9px; font-size: 12.5px; font-family: inherit; }
.line-edit-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }
.line-edit-input-narrow { width: 70px; min-width: 70px; }
.required-dot { color: var(--red); font-weight: 700; }
.invoice-lines-save-row { display: flex; align-items: center; gap: 12px; margin: 12px 0 24px; flex-wrap: wrap; }

.invoice-totals { display: flex; justify-content: flex-end; margin: 20px 0; }
.invoice-totals-box { width: 300px; }
.invoice-totals-box .field-row { font-size: 13.5px; }
.invoice-total-grand { border-top: 2px solid var(--text); border-bottom: none; margin-top: 6px; padding-top: 10px; font-weight: 700; font-size: 15px; }

.invoice-payment-terms { font-size: 13px; color: var(--muted); background: #fafbfe; border-radius: var(--radius-sm); padding: 12px 16px; margin-top: 8px; }

.invoice-extra-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-top: 28px; padding-top: 24px; border-top: 1px solid var(--border); }
@media (max-width: 760px) {
  .invoice-parties, .invoice-extra-fields { grid-template-columns: 1fr; }
}
.truncate-cell {
    max-width: 180px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    /*display: flex;*/
    align-items: center;
    gap: 4px;
}

.truncate-cell-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.truncate-info-icon {
    display: none;
    flex-shrink: 0;
    padding-right: 2px;
    color: var(--muted);
    font-size: 12px;
    cursor: default;
}

.truncate-cell.is-truncated .truncate-info-icon {
    display: inline-block;
}