/* GoticTeam Accounting — application theme */
:root {
    /* GOTIC brand — golden-yellow on near-black */
    --brand: #F5C21B;
    --brand-dark: #d9a400;
    --ink: #15161a;
    --ink-2: #23252c;
    --bg: #f5f6f8;
    --surface: #ffffff;
    --sidebar: #15161a;
    --sidebar-2: #26282f;
    --sidebar-text: #b9bcc4;
    --sidebar-active: #F5C21B;
    --primary: #F5C21B;
    --primary-dark: #d9a400;
    --primary-ink: #15161a;
    --link: #1d4ed8;
    --text: #1f2430;
    --muted: #6b7280;
    --border: #e6e8ec;
    --green: #16a34a;
    --green-bg: #dcfce7;
    --amber: #d97706;
    --amber-bg: #fef3c7;
    --red: #dc2626;
    --red-bg: #fee2e2;
    --blue: #2563eb;
    --blue-bg: #dbeafe;
    --gold-bg: #fdf3d0;
    --gold-text: #8a6d00;
    --gray-bg: #f1f3f5;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(15,20,30,.08), 0 1px 2px rgba(15,20,30,.04);
    --shadow-lg: 0 14px 34px -8px rgba(15,20,30,.22);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1,h2,h3,h4 { margin: 0 0 .5rem; font-weight: 600; color: var(--text); }

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
    width: 250px; background: var(--sidebar); color: var(--sidebar-text);
    display: flex; flex-direction: column; position: fixed; top: 0; bottom: 0; left: 0; z-index: 40;
}
.sidebar .brand {
    padding: 20px; font-size: 18px; font-weight: 700; color: #fff;
    display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--sidebar-2);
}
.sidebar .brand .logo {
    width: 32px; height: 32px; border-radius: 8px; background: var(--primary);
    display: grid; place-items: center; font-size: 16px;
}
.nav { padding: 12px 8px; overflow-y: auto; flex: 1; scrollbar-width: thin; scrollbar-color: #3a3d46 transparent; overscroll-behavior: contain; }
.nav::-webkit-scrollbar { width: 6px; }
.nav::-webkit-scrollbar-track { background: transparent; }
.nav::-webkit-scrollbar-thumb { background: #34363f; border-radius: 999px; }
.nav::-webkit-scrollbar-thumb:hover { background: var(--brand); }
/* Hide the scrollbar until the sidebar is hovered, for a cleaner look */
.nav { scrollbar-color: transparent transparent; }
.sidebar:hover .nav { scrollbar-color: #3a3d46 transparent; }
.nav::-webkit-scrollbar-thumb { background: transparent; }
.sidebar:hover .nav::-webkit-scrollbar-thumb { background: #34363f; }
.sidebar:hover .nav::-webkit-scrollbar-thumb:hover { background: var(--brand); }
.nav .group-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #64748b; padding: 14px 12px 6px; }
.nav a {
    display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px;
    color: var(--sidebar-text); font-weight: 500; margin-bottom: 2px;
}
.nav a:hover { background: var(--sidebar-2); color: #fff; text-decoration: none; }
.nav a.active { background: var(--brand); color: var(--ink); font-weight: 700; }
.nav a.active .ico { opacity: 1; }
.nav a .ico { width: 18px; text-align: center; opacity: .9; }

.main { flex: 1; margin-left: 250px; display: flex; flex-direction: column; min-width: 0; }
.topbar {
    height: 60px; background: var(--surface); border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between; padding: 0 24px; position: sticky; top: 0; z-index: 30;
}
.topbar .page-title { font-size: 16px; font-weight: 600; }
.topbar .user { display: flex; align-items: center; gap: 12px; }
.avatar {
    width: 34px; height: 34px; border-radius: 50%; background: var(--brand); color: var(--ink);
    display: grid; place-items: center; font-weight: 700; font-size: 13px;
}
.content { padding: 24px; flex: 1; }
/* Consistent vertical rhythm between top-level page blocks (cards, grids, split rows, page-head). */
.content > * + * { margin-top: 20px; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card + .card { margin-top: 20px; }
.card-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.card-head h3 { margin: 0; font-size: 15px; }
.card-body { padding: 20px; }
.card-body.tight { padding: 0; }

/* ---------- KPI ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.kpi .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 24px; font-weight: 700; margin-top: 6px; }
.kpi .sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.kpi.accent { border-top: 3px solid var(--primary); }
.kpi.green .value { color: var(--green); }
.kpi.red .value { color: var(--red); }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px;
    border: 1px solid transparent; font-weight: 600; font-size: 13px; cursor: pointer; background: var(--gray-bg); color: var(--text);
    transition: all .15s; text-decoration: none;
}
.btn:hover { text-decoration: none; filter: brightness(.98); }
.btn-primary { background: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--green); color: #fff; }
.btn-danger { background: var(--red); color: #fff; }
.btn-warning { background: var(--amber); color: #fff; }
.btn-outline { background: #fff; border-color: var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--muted); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; }
table.data th, table.data td { padding: 11px 16px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.data th { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: #fafbfc; font-weight: 600; }
table.data tbody tr:hover { background: #fafbfc; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tfoot td { font-weight: 700; border-top: 2px solid var(--border); }
.text-muted { color: var(--muted); }
.text-right { text-align: right; }
.mono { font-variant-numeric: tabular-nums; }

/* Contract list: keep every field visible without horizontal scrolling. */
.table-wrap.subscription-contracts-wrap { overflow-x: visible; }
.subscription-contracts-table { table-layout: fixed; }
table.subscription-contracts-table th, table.subscription-contracts-table td {
    padding: 11px 9px; white-space: normal; overflow-wrap: anywhere; vertical-align: top;
}
.subscription-contracts-table th:nth-child(1) { width: 14%; }
.subscription-contracts-table th:nth-child(2) { width: 17%; }
.subscription-contracts-table th:nth-child(3) { width: 21%; }
.subscription-contracts-table th:nth-child(4) { width: 21%; }
.subscription-contracts-table th:nth-child(5) { width: 11%; }
.subscription-contracts-table th:nth-child(6) { width: 8%; }
.subscription-contracts-table th:nth-child(7) { width: 8%; }
.subscription-contracts-table .text-muted { margin-top: 3px; line-height: 1.35; }
table.subscription-contracts-table td.contract-open { text-align: right; }
table.subscription-contracts-table td.contract-open .btn {
    min-width: 58px; justify-content: center; white-space: nowrap;
}

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge-green { background: var(--green-bg); color: var(--green); }
.badge-amber { background: var(--amber-bg); color: var(--amber); }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-blue { background: var(--blue-bg); color: var(--blue); }
.badge-gray { background: var(--gray-bg); color: var(--muted); }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.form-grid .full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 4px; }
.field label { font-weight: 600; font-size: 13px; }
.field .hint { font-size: 12px; color: var(--muted); }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], select, textarea {
    width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px;
    font-size: 14px; font-family: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(245,194,27,.28); }
textarea { resize: vertical; min-height: 70px; }
.checkbox { display: flex; align-items: center; gap: 8px; }
.checkbox input { width: auto; }
.form-actions { display: flex; gap: 10px; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }

/* ---------- Line items editor ---------- */
table.items { width: 100%; border-collapse: collapse; }
table.items th, table.items td { padding: 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.items th { font-size: 11px; text-transform: uppercase; color: var(--muted); text-align: left; }
table.items input, table.items select, table.items textarea { padding: 7px 9px; }
table.items td.num input { text-align: right; }
table.items textarea { min-height: 38px; line-height: 1.4; resize: vertical; }
table.items td.li-desc { min-width: 220px; }
.line-remove { color: var(--red); cursor: pointer; background: none; border: none; font-size: 18px; line-height: 1; }
.billing-cell { min-width: 145px; vertical-align: top; }
.billing-frequency { display: grid; gap: 5px; margin-top: 5px; }
.billing-cell select, .billing-cell input, .billing-start input { width: 100%; min-width: 0; }
.billing-start { min-width: 138px; vertical-align: top; }
[data-recurring-control][hidden], [data-custom-interval][hidden], [data-group-interval][hidden],
[data-group-term-cycles][hidden], [data-group-term-end][hidden], [data-renewal-field][hidden] { display: none !important; }
.items .drag-cell { width: 26px; min-width: 26px; text-align: center; padding-left: 4px; padding-right: 4px; }
.items .drag-handle { cursor: grab; user-select: none; color: var(--muted); font-size: 16px; line-height: 1; display: inline-block; padding: 6px 2px; }
.items .drag-handle:active { cursor: grabbing; color: var(--brand-dark); }
table.items tr[data-line-row].dragging { opacity: .6; }
table.items tr[data-line-row].dragging td { background: var(--gold-bg); }
.totals-box { max-width: 320px; margin-left: auto; margin-top: 16px; }
.totals-box .row { display: flex; justify-content: space-between; padding: 6px 0; }
.totals-box .row.grand { border-top: 2px solid var(--border); margin-top: 6px; padding-top: 10px; font-size: 18px; font-weight: 700; }

/* ---------- Manual subscription contract ---------- */
.table-wrap.manual-contract-services-wrap { overflow-x: visible; }
.manual-contract-services { table-layout: fixed; min-width: 0 !important; }
.manual-contract-services th:nth-child(1) { width: 34%; }
.manual-contract-services th:nth-child(2) { width: 9%; }
.manual-contract-services th:nth-child(3) { width: 14%; }
.manual-contract-services th:nth-child(4) { width: 14%; }
.manual-contract-services th:nth-child(5) { width: 10%; }
.manual-contract-services th:nth-child(6) { width: 14%; }
.manual-contract-services th:nth-child(7) { width: 5%; }
.manual-contract-services td { min-width: 0; }
.manual-contract-services input, .manual-contract-services select { min-width: 0; }
.manual-service-total { font-weight: 700; font-variant-numeric: tabular-nums; }
.manual-service-remove { text-align: center; }
.manual-contract-actions { justify-content: flex-end; }

/* ---------- Flash ---------- */
.flash-wrap { display: flex; flex-direction: column; gap: 8px; }
/* In the auth card there's no .content flow rule, so keep an explicit gap below flashes. */
.auth-card .flash-wrap { margin-bottom: 16px; }
.flash { padding: 12px 16px; border-radius: 8px; font-weight: 500; display: flex; align-items: center; gap: 10px; }
.flash.success { background: var(--green-bg); color: #166534; }
.flash.error { background: var(--red-bg); color: #991b1b; }
.flash.info { background: var(--blue-bg); color: #1e40af; }
.contract-activation-notice { justify-content: space-between; flex-wrap: wrap; }
.contract-activation-notice > div { min-width: min(100%, 320px); flex: 1; }
.contract-activation-notice strong { display: block; margin-bottom: 2px; }
.contract-activation-notice .btn { flex: 0 0 auto; background: #fff; }

.field-label-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 7px;
}
.field-label-row label { margin-bottom: 0; }
.field-help {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 17px;
    width: 17px;
    height: 17px;
    padding: 0;
    border: 1px solid #94a3b8;
    border-radius: 50%;
    background: #fff;
    color: #475569;
    font: 700 11px/1 Arial, sans-serif;
    cursor: help;
    vertical-align: middle;
}
.field-help:hover,
.field-help:focus-visible {
    border-color: #2563eb;
    color: #1d4ed8;
    outline: none;
}
.field-help-tooltip {
    position: absolute;
    z-index: 80;
    left: 50%;
    bottom: calc(100% + 8px);
    width: max-content;
    max-width: min(280px, calc(100vw - 48px));
    padding: 8px 10px;
    border-radius: 6px;
    background: #111827;
    color: #fff;
    box-shadow: 0 8px 20px rgba(15, 23, 42, .18);
    font: 500 12px/1.45 Arial, sans-serif;
    text-align: left;
    white-space: normal;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translate(calc(-50% + var(--field-help-offset, 0px)), 3px);
    transition: opacity .12s ease, transform .12s ease, visibility .12s ease;
}
.field-help:hover .field-help-tooltip,
.field-help:focus-visible .field-help-tooltip {
    opacity: 1;
    visibility: visible;
    transform: translate(calc(-50% + var(--field-help-offset, 0px)), 0);
}
th .field-help { margin-left: 3px; }

@media print {
    .field-help { display: none !important; }
}

/* ---------- Page header ---------- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; margin: 0; }
.page-head .actions { display: flex; gap: 10px; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar form { display: flex; gap: 8px; }

/* ---------- Auth ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px;
    background: radial-gradient(1200px 500px at 50% -10%, rgba(245,194,27,.18), transparent 60%), linear-gradient(160deg, #15161a, #26282f); }
.auth-card { text-align: left; }
.auth-card .brand-head { display: flex; flex-direction: column; align-items: center; text-align: center; margin-bottom: 18px; }
.auth-card .brand-head h1 { font-size: 20px; margin: 10px 0 2px; letter-spacing: .04em; }
.auth-card { background: #fff; border-radius: 16px; box-shadow: var(--shadow-lg); width: 100%; max-width: 420px; padding: 36px; }
.auth-card .brand { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.auth-card .brand .logo { width: 40px; height: 40px; border-radius: 10px; background: var(--primary); color: #fff; display: grid; place-items: center; font-size: 20px; font-weight: 700; }
.auth-card h1 { font-size: 20px; }
.auth-card .sub { color: var(--muted); margin-bottom: 24px; }

/* ---------- Document view ---------- */
.doc { background: #fff; }
.doc-header { display: flex; justify-content: space-between; align-items: flex-start; padding: 28px; border-bottom: 2px solid var(--border); }
.doc-header .company h2 { font-size: 20px; margin-bottom: 4px; }
.doc-header .doc-meta { text-align: right; }
.doc-header .doc-meta h1 { font-size: 26px; color: var(--primary); text-transform: uppercase; letter-spacing: .04em; }
.doc-parties { display: flex; justify-content: space-between; padding: 24px 28px; gap: 24px; }
.doc-parties .block .k { font-size: 11px; text-transform: uppercase; color: var(--muted); margin-bottom: 4px; }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px,1fr)); gap: 4px 24px; }
.detail-grid .item { padding: 6px 0; }
.detail-grid .item .k { font-size: 11px; text-transform: uppercase; color: var(--muted); }
.detail-grid .item .v { font-weight: 600; }
.method-option {
    display: flex; gap: 10px; align-items: flex-start; padding: 10px 0;
    border-bottom: 1px solid var(--border);
}
.method-option:last-child { border-bottom: none; }
.method-option input { margin-top: 4px; }
.method-option small { display: block; color: var(--muted); white-space: pre-line; margin-top: 3px; line-height: 1.4; }

/* Document line items (quotation / invoice / bill): wrap long descriptions
   instead of forcing a horizontal scroll that hides the amount columns. */
.doc .table-wrap { overflow-x: visible; }
.doc table.data { table-layout: fixed; }
.doc table.data th, .doc table.data td { vertical-align: top; }
.doc table.data th:first-child, .doc table.data td:first-child {
    white-space: normal; overflow-wrap: anywhere; word-break: break-word;
}
.doc table.data th.col-qty,   .doc table.data td.col-qty   { width: 68px; }
.doc table.data th.col-price, .doc table.data td.col-price { width: 120px; }
.doc table.data th.col-tax,   .doc table.data td.col-tax   { width: 64px; }
.doc table.data th.col-amt,   .doc table.data td.col-amt   { width: 130px; }
.doc .line-title { font-weight: 600; }
.doc .line-desc { color: var(--muted); font-size: 12px; margin-top: 3px; line-height: 1.45; white-space: pre-line; }
.doc .line-points { color: var(--muted); font-size: 12px; margin: 4px 0 0; padding-left: 18px; line-height: 1.5; }
.doc .line-points li { margin: 1px 0; }
.letter-body { padding: 22px 28px; font-size: 15px; line-height: 1.7; }
.letter-body p { margin: 0 0 14px; }
.amount-callout {
    display: flex; align-items: center; justify-content: space-between; gap: 18px;
    border: 1px solid var(--border); border-left: 4px solid var(--brand);
    padding: 14px 16px; margin: 18px 0; background: #fffdf4;
}
.amount-callout span { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.amount-callout strong { font-size: 22px; color: var(--ink); font-variant-numeric: tabular-nums; }
.payment-letter table.data td { white-space: normal; vertical-align: top; }

.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty .icon { font-size: 40px; opacity: .4; }
.split { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }

/* ---------- Subscription billing activity ---------- */
.table-wrap.billing-batches-wrap { overflow-x: visible; }
.billing-batches-table { table-layout: fixed; }
table.billing-batches-table > thead > tr > th,
table.billing-batches-table > tbody > tr.billing-batch-row > td {
    padding: 11px 9px; white-space: normal; overflow-wrap: anywhere; vertical-align: middle;
}
.billing-batches-table > thead th { white-space: nowrap; overflow-wrap: normal; }
.billing-batches-table > thead th:nth-child(1) { width: 7%; }
.billing-batches-table > thead th:nth-child(2) { width: 12%; }
.billing-batches-table > thead th:nth-child(3) { width: 29%; }
.billing-batches-table > thead th:nth-child(4) { width: 8%; }
.billing-batches-table > thead th:nth-child(5) { width: 10%; }
.billing-batches-table > thead th:nth-child(6) { width: 14%; }
.billing-batches-table > thead th:nth-child(7) { width: 12%; }
.billing-batches-table > thead th:nth-child(8) { width: 8%; }
.billing-batch-row .text-muted { margin-top: 3px; font-size: 11px; line-height: 1.35; }
.billing-batches-table .badge { white-space: nowrap; }
.billing-batch-amount { white-space: nowrap !important; }
.billing-batch-actions { display: flex; justify-content: flex-end; align-items: center; gap: 7px; }
.billing-batch-toggle {
    width: 34px; height: 34px; flex: 0 0 34px; display: inline-grid; place-items: center;
    border: 1px solid var(--border); border-radius: 8px; background: #fff; color: var(--text);
    cursor: pointer; font-size: 15px;
}
.billing-batch-toggle:hover { border-color: var(--muted); background: #fafbfc; }
.billing-batch-toggle span { display: block; transition: transform .15s; }
.billing-batch-toggle.is-open span { transform: rotate(180deg); }
table.billing-batches-table > tbody > tr.billing-batch-detail-row > td { padding: 0; white-space: normal; }
.billing-batch-detail { padding: 16px 18px 18px; background: #fafbfc; border-bottom: 1px solid var(--border); }
.billing-batch-detail .flash { margin-bottom: 12px; }
.billing-batch-next { margin-bottom: 12px; color: var(--muted); font-size: 12px; }
.billing-batch-totals { display: flex; gap: 18px; flex-wrap: wrap; margin-bottom: 12px; color: var(--muted); font-size: 12px; }
.billing-batch-totals strong { margin-left: 4px; color: var(--text); }
.billing-batch-services-wrap { overflow-x: visible; border: 1px solid var(--border); background: #fff; }
.billing-batch-services { table-layout: fixed; }
table.billing-batch-services th, table.billing-batch-services td {
    padding: 9px 10px; white-space: normal; overflow-wrap: anywhere; vertical-align: top;
}
.billing-batch-services th:nth-child(1) { width: 7%; }
.billing-batch-services th:nth-child(2) { width: 13%; }
.billing-batch-services th:nth-child(3) { width: 19%; }
.billing-batch-services th:nth-child(4) { width: 13%; }
.billing-batch-services th:nth-child(5) { width: 20%; }
.billing-batch-services th:nth-child(6) { width: 17%; }
.billing-batch-services th:nth-child(7) { width: 11%; }
.billing-batch-services .text-muted { margin-top: 2px; font-size: 11px; }
.billing-run-amount { white-space: nowrap !important; }
.billing-run-amount strong, .billing-run-amount span { display: block; }
.billing-run-amount span { margin-top: 3px; color: var(--muted); font-size: 11px; }

/* ---------- Subscription billing groups ---------- */
.section-head { display: flex; align-items: center; justify-content: space-between; margin: 24px 0 10px; }
.section-head h2 { margin: 0; font-size: 18px; }
.billing-group-create { margin: 16px 0 22px; }
.billing-group-create > summary { display: inline-flex; list-style: none; cursor: pointer; }
.billing-group-create > summary::-webkit-details-marker { display: none; }
.billing-group-create > form { margin-top: 10px; padding: 18px; border: 1px solid var(--border); border-radius: 8px; background: #fff; }
.billing-groups { display: grid; gap: 14px; }
.empty-band { padding: 32px 20px; text-align: center; color: var(--muted); border: 1px dashed var(--border); background: #fff; }
.billing-group { container: billing-group / inline-size; background: #fff; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; transition: border-color .15s, box-shadow .15s; }
.billing-group.drag-over { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(245,194,27,.2); }
.billing-group-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.billing-group-title { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.billing-group-title h3 { margin: 0; font-size: 16px; }
.billing-group-meta { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 5px; color: var(--muted); font-size: 12px; }
.billing-group-drop { min-height: 74px; }
.billing-group-services { table-layout: fixed; }
.billing-group-services.is-editing { min-width: 980px; }
.billing-group-services th, .billing-group-services td { padding-left: 9px; padding-right: 9px; }
.billing-group-services td { white-space: normal; overflow-wrap: anywhere; vertical-align: middle; }
.billing-group-services td.num { white-space: nowrap; overflow-wrap: normal; }
.billing-group-services .service-name-col strong,
.billing-group-services .service-name-col .text-muted { display: block; max-width: 100%; white-space: normal; overflow-wrap: anywhere; }
.billing-group-services .drag-col { width: 30px; text-align: center; }
.billing-group-services.is-editing th:nth-child(2) { width: auto; }
.billing-group-services.is-editing th:nth-child(3) { width: 58px; }
.billing-group-services.is-editing th:nth-child(4) { width: 105px; }
.billing-group-services.is-editing th:nth-child(5) { width: 82px; }
.billing-group-services.is-editing th:nth-child(6) { width: 68px; }
.billing-group-services.is-editing th:nth-child(7) { width: 128px; }
.billing-group-services.is-editing th:nth-child(8) { width: 86px; }
.billing-group-services .service-move-col { width: 232px; min-width: 232px; }
.billing-group-services .service-action-col { width: 126px; min-width: 126px; white-space: nowrap; }
.billing-group-services.is-view th:nth-child(1) { width: 31%; }
.billing-group-services.is-view th:nth-child(2) { width: 7%; }
.billing-group-services.is-view th:nth-child(3) { width: 13%; }
.billing-group-services.is-view th:nth-child(4) { width: 9%; }
.billing-group-services.is-view th:nth-child(5) { width: 8%; }
.billing-group-services.is-view th:nth-child(6) { width: 15%; }
.billing-group-services.is-view th:nth-child(7) { width: 9%; }
.billing-group-services.is-view th:nth-child(8) { width: 8%; }
.group-drag-handle { display: inline-block; padding: 5px; color: var(--muted); cursor: grab; user-select: none; font-weight: 700; }
.billing-group-services tr.dragging { opacity: .35; }
[data-service-group-form] { display: grid; grid-template-columns: minmax(130px, 1fr) auto; align-items: center; gap: 6px; width: 100%; min-width: 0; }
[data-service-group-form] select { width: 100%; min-width: 0; }
[data-service-group-form] .btn { position: static; white-space: nowrap; }

/* Contract service rows respond to the available card width, including the sidebar. */
@container billing-group (max-width: 1100px) {
    .billing-group-head { align-items: stretch; flex-direction: column; }
    .billing-group-head .actions .btn { width: 100%; }
    .billing-group-drop .table-wrap { overflow-x: visible; }
    .billing-group-services.is-editing, .billing-group-services.is-view, .billing-group-services tbody { display: block; width: 100%; min-width: 0; }
    .billing-group-services thead { display: none; }
    .billing-group-services tbody tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 14px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
    .billing-group-services tbody tr:last-child { border-bottom: 0; }
    .billing-group-services tbody td { display: block; min-width: 0; padding: 0; border: 0; white-space: normal; overflow-wrap: anywhere; }
    .billing-group-services .drag-col { display: none; }
    .billing-group-services tbody td:not(.empty)::before { display: block; margin-bottom: 3px; color: var(--muted); font-size: 10px; font-weight: 700; text-transform: uppercase; }
    .billing-group-services.is-editing tbody td:nth-child(2)::before { content: 'Service'; }
    .billing-group-services.is-editing tbody td:nth-child(3)::before { content: 'Qty'; }
    .billing-group-services.is-editing tbody td:nth-child(4)::before { content: 'Unit price'; }
    .billing-group-services.is-editing tbody td:nth-child(5)::before { content: 'Discount'; }
    .billing-group-services.is-editing tbody td:nth-child(6)::before { content: 'Tax'; }
    .billing-group-services.is-editing tbody td:nth-child(7)::before { content: 'Total / invoice'; }
    .billing-group-services.is-editing tbody td:nth-child(8)::before { content: 'Status'; }
    .billing-group-services.is-editing tbody td:nth-child(9)::before { content: 'Move to group'; }
    .billing-group-services.is-editing tbody td:nth-child(9), .billing-group-services.is-editing tbody td:nth-child(10), .billing-group-services tbody td.empty { grid-column: 1 / -1; }
    .billing-group-services.is-view tbody td:nth-child(1)::before { content: 'Service'; }
    .billing-group-services.is-view tbody td:nth-child(2)::before { content: 'Qty'; }
    .billing-group-services.is-view tbody td:nth-child(3)::before { content: 'Unit price'; }
    .billing-group-services.is-view tbody td:nth-child(4)::before { content: 'Discount'; }
    .billing-group-services.is-view tbody td:nth-child(5)::before { content: 'Tax'; }
    .billing-group-services.is-view tbody td:nth-child(6)::before { content: 'Total / invoice'; }
    .billing-group-services.is-view tbody td:nth-child(7)::before { content: 'Status'; }
    .billing-group-services.is-view tbody td:nth-child(8) { grid-column: 1 / -1; }
    [data-service-group-form] { grid-template-columns: minmax(0, 1fr) auto; min-width: 0; }
    .billing-group-services .service-move-col, .billing-group-services .service-action-col { width: auto; min-width: 0; }
    .billing-group-services.is-editing tbody td:nth-child(10) .btn, .billing-group-services.is-view tbody td:nth-child(8) .btn { width: 100%; }
}
@container billing-group (max-width: 520px) {
    .billing-group-services tbody tr { grid-template-columns: 1fr; }
    .billing-group-services.is-editing tbody td:nth-child(9), .billing-group-services.is-editing tbody td:nth-child(10), .billing-group-services.is-view tbody td:nth-child(8) { grid-column: auto; }
}
.billing-group-settings { border-top: 1px solid var(--border); padding: 0 18px 16px; }
.billing-group-settings > summary { cursor: pointer; color: var(--muted); font-weight: 600; padding: 12px 0 0; }
.billing-group-settings > form { margin-top: 14px; }
.billing-group-delete { padding-top: 12px; border-top: 1px solid var(--border); }
.group-schedule-summary { padding: 11px 12px; border-left: 3px solid var(--brand); background: var(--gold-bg); color: var(--ink); }
.service-price-summary, .schedule-preview {
    display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0;
    margin-top: 20px; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
}
.service-price-summary > div, .schedule-preview > div { min-width: 0; padding: 13px 16px; border-right: 1px solid var(--border); }
.service-price-summary > div:last-child, .schedule-preview > div:last-child { border-right: 0; }
.service-price-summary span, .schedule-preview span { display: block; margin-bottom: 4px; color: var(--muted); font-size: 11px; text-transform: uppercase; }
.service-price-summary strong, .schedule-preview strong { display: block; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.service-price-summary .service-price-total { background: var(--gold-bg); }
.service-price-summary .service-price-total strong { font-size: 18px; }
.compact-actions { margin: 0; padding: 0; border: 0; }

/* ---------- Responsive ---------- */
@media (max-width: 1180px) {
    .subscription-contracts-table, .subscription-contracts-table tbody { display: block; width: 100%; }
    .subscription-contracts-table thead { display: none; }
    .subscription-contracts-table tbody tr {
        display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 14px 20px; padding: 16px 18px; border-bottom: 1px solid var(--border);
    }
    .subscription-contracts-table tbody tr:last-child { border-bottom: 0; }
    .subscription-contracts-table tbody td {
        display: block; min-width: 0; padding: 0; border: 0; white-space: normal; overflow-wrap: anywhere;
    }
    .subscription-contracts-table tbody td:not(.empty):not(.contract-open)::before {
        content: attr(data-label); display: block; margin-bottom: 4px; color: var(--muted);
        font-size: 10px; font-weight: 700; text-transform: uppercase;
    }
    .subscription-contracts-table tbody td.contract-open { grid-column: 1 / -1; }
    .subscription-contracts-table tbody td.empty { grid-column: 1 / -1; }

    .billing-batches-table, .billing-batches-table > tbody { display: block; width: 100%; }
    .billing-batches-table > thead { display: none; }
    .billing-batches-table > tbody.billing-batch { border-bottom: 1px solid var(--border); }
    .billing-batches-table > tbody.billing-batch:last-child { border-bottom: 0; }
    .billing-batches-table > tbody > tr.billing-batch-row {
        display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 14px 20px; padding: 16px 18px;
    }
    table.billing-batches-table > tbody > tr.billing-batch-row > td {
        display: block; min-width: 0; padding: 0; border: 0; text-align: left;
    }
    .billing-batch-row > td:not(.billing-batch-actions)::before {
        content: attr(data-label); display: block; margin-bottom: 4px; color: var(--muted);
        font-size: 10px; font-weight: 700; text-transform: uppercase;
    }
    .billing-batch-row > td.billing-batch-actions { grid-column: 1 / -1; justify-content: flex-end; }
    .billing-batches-table > tbody > tr.billing-batch-detail-row:not([hidden]) { display: block; }
    .billing-batches-table > tbody > tr.billing-batch-detail-row > td { display: block; }
    .billing-batches-table > tbody > tr > td.empty { display: block; width: 100%; }

    .upcoming-billing-wrap { overflow-x: visible; }
    .upcoming-billing-table, .upcoming-billing-table tbody { display: block; width: 100%; }
    .upcoming-billing-table thead { display: none; }
    .upcoming-billing-table tbody tr {
        display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 14px 20px; padding: 16px 18px; border-bottom: 1px solid var(--border);
    }
    .upcoming-billing-table tbody tr:last-child { border-bottom: 0; }
    table.upcoming-billing-table tbody td {
        display: block; min-width: 0; padding: 0; border: 0; text-align: left;
        white-space: normal; overflow-wrap: anywhere;
    }
    .upcoming-billing-table tbody td:not(.empty)::before {
        content: attr(data-label); display: block; margin-bottom: 4px; color: var(--muted);
        font-size: 10px; font-weight: 700; text-transform: uppercase;
    }
    .upcoming-billing-table tbody td.empty { grid-column: 1 / -1; }

    .billing-group-head { align-items: stretch; flex-direction: column; }
    .billing-group-head .actions .btn { width: 100%; }
    .billing-group-drop .table-wrap { overflow-x: visible; }
    .billing-group-services.is-editing, .billing-group-services.is-view, .billing-group-services tbody { display: block; width: 100%; min-width: 0; }
    .billing-group-services thead { display: none; }
    .billing-group-services tbody tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 14px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
    .billing-group-services tbody tr:last-child { border-bottom: 0; }
    .billing-group-services tbody td { display: block; min-width: 0; padding: 0; border: 0; white-space: normal; overflow-wrap: anywhere; }
    .billing-group-services .drag-col { display: none; }
    .billing-group-services tbody td:not(.empty)::before { display: block; margin-bottom: 3px; color: var(--muted); font-size: 10px; font-weight: 700; text-transform: uppercase; }
    .billing-group-services.is-editing tbody td:nth-child(2)::before { content: 'Service'; }
    .billing-group-services.is-editing tbody td:nth-child(3)::before { content: 'Qty'; }
    .billing-group-services.is-editing tbody td:nth-child(4)::before { content: 'Unit price'; }
    .billing-group-services.is-editing tbody td:nth-child(5)::before { content: 'Discount'; }
    .billing-group-services.is-editing tbody td:nth-child(6)::before { content: 'Tax'; }
    .billing-group-services.is-editing tbody td:nth-child(7)::before { content: 'Total / invoice'; }
    .billing-group-services.is-editing tbody td:nth-child(8)::before { content: 'Status'; }
    .billing-group-services.is-editing tbody td:nth-child(9)::before { content: 'Move to group'; }
    .billing-group-services.is-editing tbody td:nth-child(9), .billing-group-services.is-editing tbody td:nth-child(10), .billing-group-services tbody td.empty { grid-column: 1 / -1; }
    .billing-group-services.is-view tbody td:nth-child(1)::before { content: 'Service'; }
    .billing-group-services.is-view tbody td:nth-child(2)::before { content: 'Qty'; }
    .billing-group-services.is-view tbody td:nth-child(3)::before { content: 'Unit price'; }
    .billing-group-services.is-view tbody td:nth-child(4)::before { content: 'Discount'; }
    .billing-group-services.is-view tbody td:nth-child(5)::before { content: 'Tax'; }
    .billing-group-services.is-view tbody td:nth-child(6)::before { content: 'Total / invoice'; }
    .billing-group-services.is-view tbody td:nth-child(7)::before { content: 'Status'; }
    .billing-group-services.is-view tbody td:nth-child(8) { grid-column: 1 / -1; }
    [data-service-group-form] { grid-template-columns: minmax(0, 1fr) auto; min-width: 0; }
    .billing-group-services .service-move-col, .billing-group-services .service-action-col { width: auto; min-width: 0; }
    .billing-group-services.is-editing tbody td:nth-child(10) .btn, .billing-group-services.is-view tbody td:nth-child(8) .btn { width: 100%; }
}

@media (max-width: 900px) {
    .sidebar { transform: translateX(-100%); transition: transform .2s; }
    .sidebar.open { transform: translateX(0); }
    .main { margin-left: 0; }
    .menu-toggle { display: inline-flex !important; }
    .form-grid, .split { grid-template-columns: 1fr; }
    .service-price-summary, .schedule-preview { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .service-price-summary > div:nth-child(2), .schedule-preview > div:nth-child(2) { border-right: 0; }
    .service-price-summary > div:nth-child(-n+2), .schedule-preview > div:nth-child(-n+2) { border-bottom: 1px solid var(--border); }
    .billing-batch-services, .billing-batch-services tbody { display: block; width: 100%; }
    .billing-batch-services thead { display: none; }
    .billing-batch-services tbody tr {
        display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px 14px; padding: 14px; border-bottom: 1px solid var(--border);
    }
    .billing-batch-services tbody tr:last-child { border-bottom: 0; }
    table.billing-batch-services tbody td {
        display: block; min-width: 0; padding: 0; border: 0; text-align: left;
    }
    .billing-batch-services tbody td::before {
        content: attr(data-label); display: block; margin-bottom: 3px; color: var(--muted);
        font-size: 10px; font-weight: 700; text-transform: uppercase;
    }

    .manual-contract-services, .manual-contract-services tbody { display: block; width: 100%; }
    .manual-contract-services thead { display: none; }
    .manual-contract-services tbody tr {
        display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 12px 14px; padding: 14px; border-bottom: 1px solid var(--border);
    }
    .manual-contract-services tbody tr:last-child { border-bottom: 0; }
    table.manual-contract-services tbody td {
        display: block; min-width: 0; padding: 0; border: 0; text-align: left;
    }
    .manual-contract-services tbody td::before {
        content: attr(data-label); display: block; margin-bottom: 3px; color: var(--muted);
        font-size: 10px; font-weight: 700; text-transform: uppercase;
    }
    .manual-contract-services tbody td.manual-service-name { grid-column: 1 / -1; }
    .manual-contract-services tbody td.manual-service-remove {
        display: flex; align-items: flex-end; justify-content: flex-end;
    }
    .manual-contract-services tbody td.manual-service-remove::before { display: none; }
}
@media (max-width: 560px) {
    .service-price-summary, .schedule-preview { grid-template-columns: 1fr; }
    .service-price-summary > div, .schedule-preview > div { border-right: 0; border-bottom: 1px solid var(--border); }
    .service-price-summary > div:last-child, .schedule-preview > div:last-child { border-bottom: 0; }
    .subscription-contracts-table tbody tr { grid-template-columns: 1fr; }
    .subscription-contracts-table tbody td.contract-open { grid-column: auto; }
    .subscription-contracts-table tbody td.contract-open .btn { width: 100%; }
    .billing-batches-table > tbody > tr.billing-batch-row,
    .billing-batch-services tbody tr { grid-template-columns: 1fr; }
    .billing-batch-row > td.billing-batch-actions { grid-column: auto; justify-content: stretch; }
    .billing-batch-actions form { flex: 1; }
    .billing-batch-actions form .btn { width: 100%; justify-content: center; }
    .manual-contract-services tbody tr { grid-template-columns: 1fr; }
    .manual-contract-services tbody td.manual-service-name { grid-column: auto; }
    .manual-contract-actions { align-items: stretch; flex-direction: column; }
    .manual-contract-actions .btn { justify-content: center; }
    .upcoming-billing-table tbody tr { grid-template-columns: 1fr; }
    .upcoming-billing-table tbody td.empty { grid-column: auto; }
    .billing-group-services tbody tr { grid-template-columns: 1fr; }
    .billing-group-services.is-editing tbody td:nth-child(9), .billing-group-services.is-editing tbody td:nth-child(10), .billing-group-services.is-view tbody td:nth-child(8) { grid-column: auto; }
}
.menu-toggle { display: none; background: none; border: none; font-size: 22px; cursor: pointer; }

/* ---------- Brand logo ---------- */
.brand .logo-img { width: 34px; height: 34px; border-radius: 8px; object-fit: cover; display: block; }
.sidebar .brand { letter-spacing: .02em; text-transform: uppercase; font-weight: 800; }
.auth-logo { width: 84px; height: 84px; border-radius: 18px; object-fit: cover; box-shadow: var(--shadow-lg); margin-bottom: 6px; }
.doc-logo { width: 74px; height: 74px; border-radius: 12px; object-fit: cover; }

/* ---------- Gold badge ---------- */
.badge-gold { background: var(--gold-bg); color: var(--gold-text); }

/* ---------- Permission grid ---------- */
.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.perm-group { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.perm-group-title { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; margin-bottom: 8px; }
.perm-item { display: flex; align-items: center; gap: 8px; padding: 3px 0; font-size: 13px; }

/* ---------- Dashboard mini bar chart ---------- */
.chart { display: flex; align-items: flex-end; gap: 10px; height: 160px; padding: 8px 4px 0; }
.chart .bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.chart .bar { width: 100%; max-width: 42px; border-radius: 6px 6px 0 0; background: linear-gradient(180deg, var(--brand), var(--brand-dark)); min-height: 3px; transition: height .3s; }
.chart .bar.expense { background: linear-gradient(180deg, #2a2c33, #15161a); }
.chart .bar-label { font-size: 11px; color: var(--muted); }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); margin-top: 10px; }
.legend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: middle; }

.kpi.brand-accent { border-top: 3px solid var(--brand); }
.kpi .value.brand { color: var(--brand-dark); }

/* ---------- Subscription lifecycle and pricing ---------- */
.billing-group-warning { margin: 0; border-radius: 0; border-width: 0 0 1px; }
.billing-group-renew { display: flex; align-items: flex-end; gap: 10px; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }
.billing-group-renew .field { margin: 0; max-width: 280px; }
.compact-preview { margin: 14px 0 0; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.compact-preview > div { padding: 10px 12px; }
.midcycle-options { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }
.pricing-version-create { margin-top: 12px; }
.pricing-version-form { display: grid; grid-template-columns: 130px 85px 125px 90px 90px 120px minmax(150px, 1fr) auto; align-items: center; gap: 8px; }
.pricing-version-form input { width: 100%; min-width: 0; }
.pricing-version-form .actions { display: flex; gap: 6px; }
.billing-batches { display: grid; gap: 10px; }
.billing-batch { background: #fff; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.billing-batch > summary { display: grid; grid-template-columns: 54px minmax(130px, 1.1fr) minmax(170px, 1.3fr) 90px 110px 120px 130px; align-items: center; gap: 12px; min-height: 72px; padding: 12px 16px; cursor: pointer; list-style: none; }
.billing-batch > summary::-webkit-details-marker { display: none; }
.billing-batch > summary:hover { background: #fafbfc; }
.billing-batch > summary small { display: block; margin-top: 3px; color: var(--muted); }
.billing-batch-body { padding: 14px 16px 16px; border-top: 1px solid var(--border); background: #fafbfc; }
.billing-batch-body .form-actions { justify-content: flex-end; margin-top: 12px; }
.batch-number { font-weight: 700; }

/* ---------- Rebuilt subscription contracts ---------- */
.page-subtitle { color: var(--muted); font-size: 13px; margin-top: 2px; }
.form-section, .dashboard-band {
    background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
}
.form-section { padding: 20px; }
.form-section > .section-head, .dashboard-band > .section-head {
    margin: 0; padding-bottom: 14px;
}
.dashboard-band > .section-head { padding: 16px 18px; border-bottom: 1px solid var(--border); }
.responsive-table { width: 100%; overflow-x: visible; }
.responsive-table table { table-layout: fixed; }
.responsive-table th, .responsive-table td {
    white-space: normal; overflow-wrap: anywhere; vertical-align: middle;
}
.responsive-table td small, .contract-identity small, .price-summary small,
.billing-occurrence small, .attention-row small {
    display: block; color: var(--muted); margin-top: 3px; line-height: 1.35;
}
.row-command { width: 74px; text-align: right !important; }
.icon-button {
    width: 32px; height: 32px; padding: 0; display: inline-grid; place-items: center;
    border: 1px solid var(--border); border-radius: 7px; background: #fff; cursor: pointer;
}
.manual-services-table th:nth-child(1) { width: 31%; }
.manual-services-table th:nth-child(2) { width: 9%; }
.manual-services-table th:nth-child(3) { width: 15%; }
.manual-services-table th:nth-child(4) { width: 15%; }
.manual-services-table th:nth-child(5) { width: 12%; }
.manual-services-table th:nth-child(6) { width: 13%; }
.manual-services-table th:nth-child(7) { width: 5%; }
.manual-services-table input, .manual-services-table select { min-width: 0; }
.inline-totals {
    display: flex; justify-content: flex-end; align-items: stretch; flex-wrap: wrap;
    border-top: 1px solid var(--border);
}
.inline-totals span { padding: 12px 16px; color: var(--muted); }
.inline-totals strong { color: var(--text); margin-left: 8px; font-variant-numeric: tabular-nums; }
.inline-totals .grand { background: var(--gold-bg); color: var(--ink); font-weight: 700; }
.price-summary {
    display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
    background: #fff; border: 1px solid var(--border); border-radius: 8px; overflow: hidden;
}
.price-summary > div { padding: 16px 18px; border-right: 1px solid var(--border); }
.price-summary > div:last-child { border-right: 0; }
.price-summary span { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; }
.price-summary strong { display: block; margin-top: 4px; font-size: 17px; font-variant-numeric: tabular-nums; }
.price-summary .total { background: var(--gold-bg); }
.price-summary .total strong { font-size: 20px; }
.static-summary { margin-top: 20px; }
.check-field { flex-direction: row; align-items: center; justify-content: flex-start; gap: 8px; padding-top: 22px; }
.check-field > label { display: flex; align-items: center; gap: 8px; min-height: 18px; }
.check-field input { width: auto; }

.contract-identity {
    display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
    background: #fff; border: 1px solid var(--border); border-radius: 8px; overflow: hidden;
}
.contract-identity > div { min-width: 0; padding: 15px 18px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.contract-identity > div:nth-child(4n) { border-right: 0; }
.contract-identity > div:nth-last-child(-n+4) { border-bottom: 0; }
.contract-identity span:first-child {
    display: block; margin-bottom: 4px; color: var(--muted); font-size: 10px;
    font-weight: 700; text-transform: uppercase;
}
.contract-identity strong { display: block; min-width: 0; overflow-wrap: anywhere; }
.service-identity { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.editor-panel {
    background: #fff; border: 1px solid var(--border); border-radius: 8px; overflow: hidden;
}
.editor-panel > summary {
    cursor: pointer; list-style: none; padding: 14px 18px; font-weight: 700;
}
.editor-panel > summary::-webkit-details-marker { display: none; }
.editor-panel[open] > summary { border-bottom: 1px solid var(--border); }
.editor-panel > form { padding: 18px; }
.subscription-groups { display: grid; gap: 20px; }
.subscription-group {
    min-width: 0; background: #fff; border: 1px solid var(--border); border-radius: 8px; overflow: hidden;
}
.subscription-group-head {
    display: flex; align-items: flex-start; justify-content: space-between; gap: 20px;
    padding: 18px 20px; border-bottom: 1px solid var(--border);
}
.subscription-group-title { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.subscription-group-title h3 { margin: 0; font-size: 18px; }
.subscription-group-meta { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 7px; color: var(--muted); font-size: 12px; }
.subscription-group-total { flex: 0 0 auto; text-align: right; }
.subscription-group-total span { display: block; color: var(--muted); font-size: 10px; font-weight: 700; text-transform: uppercase; }
.subscription-group-total strong { display: block; margin-top: 4px; font-size: 20px; }
.group-warning, .occurrence-error {
    padding: 10px 18px; border-bottom: 1px solid #f5d18a; background: var(--amber-bg); color: #92400e;
}
.group-services-table table { table-layout: fixed; }
.group-services-table th:nth-child(1) { width: 27%; }
.group-services-table th:nth-child(2) { width: 6%; }
.group-services-table th:nth-child(3) { width: 11%; }
.group-services-table th:nth-child(4) { width: 11%; }
.group-services-table th:nth-child(5) { width: 10%; }
.group-services-table th:nth-child(6) { width: 8%; }
.group-services-table th:nth-child(7) { width: 11%; }
.group-services-table th:nth-child(8) { width: 16%; }
.group-services-table td { white-space: normal; overflow-wrap: anywhere; }
.group-services-table td.num { white-space: nowrap; }
.group-services-table td small {
    display: block; margin-top: 3px; color: var(--muted); line-height: 1.35;
}
.service-row-actions { display: flex; align-items: center; justify-content: flex-end; gap: 6px; flex-wrap: wrap; }
.service-row-actions form { display: flex; align-items: center; gap: 5px; min-width: 0; }
.service-row-actions select { width: min(320px, 100%); min-width: 180px; max-width: 100%; padding: 5px 7px; font-size: 12px; }
.muted-row { opacity: .65; }
.group-actions {
    display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding: 14px 18px;
    border-top: 1px solid var(--border); background: #fafbfc;
}
.group-actions > form { display: inline-flex; }
.group-settings { width: auto; }
.group-settings > summary { list-style: none; cursor: pointer; }
.group-settings > summary::-webkit-details-marker { display: none; }
.group-settings[open] { width: 100%; order: 20; }
.group-settings[open] > summary { margin-bottom: 10px; }
.group-settings > form { padding: 16px; border: 1px solid var(--border); background: #fff; border-radius: 8px; }
.schedule-preview-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.schedule-preview-list span { padding: 5px 8px; border: 1px solid var(--border); background: #fafbfc; font-size: 12px; }
.invoice-history {
    background: #fff; border: 1px solid var(--border); border-radius: 8px; overflow: hidden;
}
.invoice-history table { table-layout: fixed; }
.invoice-history td { white-space: normal; overflow-wrap: anywhere; }
.danger-zone {
    display: flex; justify-content: space-between; align-items: center; gap: 20px;
    padding: 18px 20px; border: 1px solid #fecaca; border-radius: 8px; background: #fff;
}
.danger-zone p { margin: 3px 0 0; color: var(--muted); }

.list-toolbar {
    display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap;
}
.filter-tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.filter-tabs a { padding: 6px 9px; color: var(--muted); border-bottom: 2px solid transparent; font-size: 12px; font-weight: 600; }
.filter-tabs a:hover { text-decoration: none; color: var(--text); }
.filter-tabs a.active { color: var(--text); border-color: var(--brand); }
.list-search { display: flex; align-items: center; gap: 6px; }
.list-search input { width: min(320px, 60vw); padding-top: 6px; padding-bottom: 6px; }
.contracts-list th:nth-child(1) { width: 11%; }
.contracts-list th:nth-child(2) { width: 15%; }
.contracts-list th:nth-child(3) { width: 15%; }
.contracts-list th:nth-child(4), .contracts-list th:nth-child(5) { width: 7%; }
.contracts-list th:nth-child(6) { width: 11%; }
.contracts-list th:nth-child(7) { width: 14%; }
.contracts-list th:nth-child(8) { width: 12%; }
.contracts-list th:nth-child(9) { width: 8%; }
.dashboard-columns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.attention-row {
    display: flex; justify-content: space-between; align-items: center; gap: 14px;
    padding: 13px 16px; border-bottom: 1px solid var(--border); color: var(--text);
}
.attention-row:last-child { border-bottom: 0; }
.attention-row:hover { background: #fafbfc; text-decoration: none; }
.kpi-grid a.kpi { color: var(--text); }
.kpi-grid a.kpi:hover { text-decoration: none; border-color: #cbd5e1; }

.billing-activity { display: grid; gap: 12px; }
.billing-occurrence { background: #fff; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.billing-occurrence.requires-action { border-left: 4px solid var(--red); }
.occurrence-main {
    display: grid; grid-template-columns: minmax(250px, 2fr) minmax(120px, 1fr) 70px 130px 125px auto;
    align-items: center; gap: 16px; padding: 16px 18px;
}
.occurrence-main > div { min-width: 0; }
.occurrence-main > div > span { display: block; color: var(--muted); font-size: 10px; font-weight: 700; text-transform: uppercase; }
.occurrence-main > div > strong { display: block; margin-top: 3px; overflow-wrap: anywhere; }
.occurrence-main .eyebrow { margin-bottom: 3px; }
.audit-details { border-top: 1px solid var(--border); }
.audit-details > summary { cursor: pointer; padding: 10px 18px; color: var(--muted); font-size: 12px; font-weight: 600; }
.audit-details > .responsive-table { border-top: 1px solid var(--border); }
.audit-meta { padding: 9px 14px; color: var(--muted); background: #fafbfc; font-size: 11px; overflow-wrap: anywhere; }

@media (max-width: 1500px) {
    .contracts-list, .contracts-list tbody,
    .group-services-table table, .group-services-table tbody,
    .upcoming-groups-table, .upcoming-groups-table tbody { display: block; width: 100%; }
    .contracts-list thead, .group-services-table thead, .upcoming-groups-table thead { display: none; }
    .contracts-list tbody tr, .group-services-table tbody tr, .upcoming-groups-table tbody tr {
        display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 12px 18px; padding: 15px 18px; border-bottom: 1px solid var(--border);
    }
    .group-services-table tbody tr { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .group-services-table tbody td:first-child { grid-column: span 2; }
    .contracts-list tbody td, .group-services-table tbody td, .upcoming-groups-table tbody td {
        display: block; min-width: 0; padding: 0; border: 0; text-align: left !important;
        white-space: normal; overflow-wrap: anywhere;
    }
    .contracts-list td:not(.empty)::before, .group-services-table td:not(.empty)::before,
    .upcoming-groups-table td:not(.empty)::before {
        content: attr(data-label); display: block; margin-bottom: 3px; color: var(--muted);
        font-size: 10px; font-weight: 700; text-transform: uppercase;
    }
    .contracts-list td.row-command, .group-services-table td.service-row-actions,
    .contracts-list td.empty, .group-services-table td.empty, .upcoming-groups-table td.empty {
        grid-column: 1 / -1;
    }
    .contracts-list td.row-command { text-align: right !important; }
    .service-row-actions { justify-content: flex-start; }
    .occurrence-main { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
    .contract-identity, .service-identity { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .contract-identity > div, .contract-identity > div:nth-child(4n) { border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); }
    .contract-identity > div:nth-child(2n) { border-right: 0; }
    .contract-identity > div:nth-last-child(-n+2) { border-bottom: 0; }
    .price-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .price-summary > div:nth-child(2) { border-right: 0; }
    .price-summary > div:nth-child(-n+2) { border-bottom: 1px solid var(--border); }
    .dashboard-columns { grid-template-columns: 1fr; }
    .manual-services-table, .manual-services-table tbody { display: block; width: 100%; }
    .manual-services-table thead { display: none; }
    .manual-services-table tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; padding: 14px; border-bottom: 1px solid var(--border); }
    .manual-services-table td { display: block; min-width: 0; padding: 0; border: 0; text-align: left !important; }
    .manual-services-table td:not(.row-command)::before { content: attr(data-label); display: block; margin-bottom: 3px; color: var(--muted); font-size: 10px; font-weight: 700; text-transform: uppercase; }
    .manual-services-table td:first-child, .manual-services-table td.row-command { grid-column: 1 / -1; }
    .manual-services-table td.row-command { text-align: right !important; }
    .subscription-group-head { flex-direction: column; }
    .subscription-group-total { text-align: left; }
}

@media (max-width: 620px) {
    .content { padding: 16px; }
    .topbar { padding: 0 14px; }
    .topbar .page-title, .topbar .user-name { display: none; }
    .page-head .actions { width: 100%; flex-wrap: wrap; }
    .contract-identity, .service-identity, .price-summary { grid-template-columns: 1fr; }
    .contract-identity > div, .contract-identity > div:nth-child(2n), .contract-identity > div:nth-child(4n),
    .price-summary > div { border-right: 0; border-bottom: 1px solid var(--border); }
    .contract-identity > div:last-child, .price-summary > div:last-child { border-bottom: 0; }
    .contracts-list tbody tr, .group-services-table tbody tr, .upcoming-groups-table tbody tr,
    .occurrence-main, .manual-services-table tr { grid-template-columns: 1fr; }
    .group-services-table tbody td:first-child { grid-column: auto; }
    .contracts-list td.row-command, .group-services-table td.service-row-actions,
    .manual-services-table td:first-child, .manual-services-table td.row-command { grid-column: auto; }
    .service-row-actions, .service-row-actions form { align-items: stretch; flex-direction: column; width: 100%; }
    .service-row-actions .btn, .service-row-actions select { width: 100%; max-width: none; justify-content: center; }
    .group-actions { align-items: stretch; }
    .group-actions > a, .group-actions > form, .group-actions > form .btn, .group-actions > details { width: 100%; justify-content: center; }
    .group-settings > summary { justify-content: center; }
    .inline-totals { justify-content: stretch; flex-direction: column; }
    .inline-totals span { display: flex; justify-content: space-between; }
    .list-search { width: 100%; flex-wrap: wrap; }
    .list-search input { width: 100%; }
    .danger-zone { align-items: stretch; flex-direction: column; }
}

@media (max-width: 1100px) {
    .pricing-version-form { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .pricing-version-form .actions { grid-column: span 2; }
    .billing-batch > summary { grid-template-columns: 50px repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
    .compact-preview { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .pricing-version-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .pricing-version-form .actions { grid-column: 1 / -1; }
    .billing-group-renew { align-items: stretch; flex-direction: column; }
    .billing-batch > summary { grid-template-columns: 46px 1fr; }
    .billing-batch > summary > span:nth-child(n+3) { grid-column: 2; }
    .pricing-timeline-table, .pricing-timeline-table tbody { display: block; width: 100%; }
    .pricing-timeline-table thead { display: none; }
    .pricing-timeline-table tbody tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 14px; padding: 14px; border-bottom: 1px solid var(--border); }
    .pricing-timeline-table tbody tr:last-child { border-bottom: 0; }
    .pricing-timeline-table tbody td { display: block; min-width: 0; padding: 0; border: 0; text-align: left; white-space: normal; overflow-wrap: anywhere; }
    .pricing-timeline-table tbody td[data-label]::before { content: attr(data-label); display: block; margin-bottom: 3px; color: var(--muted); font-size: 10px; font-weight: 700; text-transform: uppercase; }
    .pricing-timeline-table tbody td[colspan] { grid-column: 1 / -1; }
}

/* ---------- Print ---------- */
/* Printable document footer (brand / website line) */
.doc-footer { text-align: center; padding: 14px 28px; border-top: 1px solid var(--border); color: var(--muted); font-size: 12px; letter-spacing: .02em; }

/* Arabic / RTL document rendering (labels + layout mirror; entered data stays as typed) */
.doc-rtl { direction: rtl; text-align: right; }
.doc-rtl .doc-meta { text-align: left; }
.doc-rtl table.data th.num, .doc-rtl table.data td.num { text-align: left; }
.doc-rtl .totals-box { margin-left: 0; margin-right: auto; }
.doc-rtl .line-points { padding-left: 0; padding-right: 18px; }

.billing-schedule-feedback {
    margin: 14px 0 0;
    padding: 11px 13px;
    border-left: 3px solid #2563eb;
    background: #eff6ff;
    color: #1e3a5f;
    font-size: 13px;
    line-height: 1.45;
}
.billing-schedule-feedback[data-state="error"] {
    border-left-color: #dc2626;
    background: #fef2f2;
    color: #991b1b;
}

@media print {
    .sidebar, .topbar, .no-print, .form-actions { display: none !important; }
    .main { margin-left: 0; }
    .content { padding: 0; }
    body { background: #fff; }
    .card { border: none; box-shadow: none; }
    /* Never clip or scroll the document on paper — let everything wrap and flow. */
    .table-wrap { overflow: visible !important; }
    .doc, .card.doc { break-inside: auto; }
    .doc table.data tr { break-inside: avoid; }
    table.data th, table.data td { white-space: normal; }
}
