:root {
    --bg: #f4f6f8;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --border: #d8dee6;
    --border-strong: #b8c2cc;
    --text: #17212b;
    --muted: #667085;
    --primary: #0f766e;
    --primary-hover: #0b5f59;
    --danger: #b42318;
    --warning: #b54708;
    --success: #027a48;
    --info: #175cd3;
}

* {
    box-sizing: border-box;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: Arial, sans-serif;
    font-size: 14px;
    line-height: 1.45;
    margin: 0;
}

a {
    color: var(--primary);
    text-decoration: none;
}

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

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

.app-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.app-header-inner {
    align-items: center;
    display: grid;
    gap: 24px;
    grid-template-columns: minmax(180px, 260px) 1fr minmax(180px, 260px);
    margin: 0 auto;
    max-width: 1320px;
    min-height: 96px;
    padding: 10px 28px;
}

.brand {
    align-items: center;
    display: inline-flex;
    flex: 0 0 auto;
    white-space: nowrap;
}

.brand img {
    display: block;
    max-height: 88px;
    max-width: 260px;
    object-fit: contain;
}

.app-nav {
    display: flex;
    gap: 4px;
    justify-content: center;
}

.menu-toggle {
    display: none;
}

.nav-link {
    border-radius: 6px;
    color: var(--muted);
    display: inline-flex;
    font-weight: 700;
    padding: 8px 10px;
}

.nav-link:hover {
    background: var(--surface-soft);
    color: var(--text);
    text-decoration: none;
}

.nav-link.active {
    background: #e6f4f1;
    color: var(--primary);
}

.user-menu {
    align-items: center;
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    white-space: nowrap;
}

.header-usage {
    align-items: flex-end;
    background: #e6f4f1;
    border: 1px solid #b7e2d8;
    border-radius: 8px;
    color: var(--primary);
    display: inline-flex;
    flex-direction: column;
    line-height: 1.15;
    min-height: 42px;
    padding: 6px 10px;
    text-align: right;
}

.header-usage:hover {
    background: #d9f0eb;
    color: var(--primary-hover);
    text-decoration: none;
}

.header-usage span {
    font-size: 12px;
    font-weight: 700;
}

.header-usage strong {
    color: var(--text);
    font-size: 14px;
}

.account-menu {
    position: relative;
}

.account-summary {
    align-items: flex-end;
    border: 1px solid transparent;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    line-height: 1.2;
    list-style: none;
    max-width: 220px;
    min-height: 42px;
    padding: 6px 10px;
    text-align: right;
}

.account-summary::-webkit-details-marker {
    display: none;
}

.account-summary:hover,
.account-menu[open] .account-summary {
    background: var(--surface-soft);
    border-color: var(--border);
}

.account-role {
    color: var(--text);
    font-weight: 700;
}

.account-email {
    color: var(--muted);
    font-size: 13px;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.account-dropdown {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.14);
    min-width: 180px;
    padding: 6px;
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    z-index: 20;
}

.account-dropdown a {
    border-radius: 6px;
    color: var(--text);
    display: block;
    font-weight: 700;
    padding: 8px 10px;
}

.account-dropdown a:hover {
    background: var(--surface-soft);
    text-decoration: none;
}

.account-dropdown a + a {
    margin-top: 2px;
}

.app-main {
    margin: 0 auto;
    max-width: 1320px;
    padding: 28px;
}

.login-page {
    align-items: center;
    display: flex;
    min-height: 100vh;
    padding: 24px;
}

.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    margin: 0 auto;
    max-width: 420px;
    padding: 24px;
    width: 100%;
}

.login-title {
    font-size: 24px;
    line-height: 1.2;
    margin: 0;
}

.login-logo {
    display: block;
    margin: 0 0 18px;
    max-height: 58px;
    max-width: 220px;
    object-fit: contain;
}

.login-subtitle {
    color: var(--muted);
    margin: 6px 0 22px;
}

.login-card .field + .field {
    margin-top: 16px;
}

.page-header {
    align-items: flex-start;
    display: flex;
    gap: 18px;
    justify-content: space-between;
    margin-bottom: 18px;
}

.page-kicker {
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
    margin: 0 0 4px;
    text-transform: uppercase;
}

.page-title {
    font-size: 26px;
    line-height: 1.2;
    margin: 0;
}

.page-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
}

.button {
    align-items: center;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    color: var(--text);
    cursor: pointer;
    display: inline-flex;
    font: inherit;
    font-weight: 700;
    min-height: 36px;
    padding: 8px 12px;
}

.button:hover {
    background: var(--surface-soft);
    color: var(--text);
    text-decoration: none;
}

.button.primary {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.button.primary:hover {
    background: var(--primary-hover);
    color: #fff;
}

.button:disabled,
.button.disabled {
    background: #eef2f6;
    border-color: var(--border);
    color: #98a2b3;
    cursor: not-allowed;
}

.button:disabled:hover,
.button.disabled:hover {
    background: #eef2f6;
    color: #98a2b3;
    text-decoration: none;
}

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
}

.panel + .panel,
.alert + .panel,
.detail-grid + .panel {
    margin-top: 18px;
}

.panel-header {
    align-items: center;
    border-bottom: 1px solid var(--border);
    display: flex;
    gap: 12px;
    justify-content: space-between;
    padding: 14px 16px;
}

.panel-title {
    font-size: 16px;
    margin: 0;
}

.panel-body {
    padding: 16px;
}

.detail-grid {
    display: grid;
    gap: 18px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin-top: 18px;
}

.detail-list {
    margin: 0;
}

.detail-list div {
    display: grid;
    gap: 12px;
    grid-template-columns: 150px 1fr;
    padding: 4px 0;
}

.detail-list dt {
    color: var(--muted);
    font-weight: 700;
}

.detail-list dd {
    margin: 0;
}

.summary-grid {
    display: grid;
    gap: 10px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.summary-card {
    background: var(--surface-soft);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
}

.summary-card strong {
    display: block;
    font-size: 20px;
    margin-top: 4px;
}

.dashboard-grid {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    margin-bottom: 18px;
}

.metric-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px;
}

.metric-card span,
.month-totals span {
    color: var(--muted);
    display: block;
    font-size: 13px;
    font-weight: 700;
}

.metric-card strong {
    display: block;
    font-size: 28px;
    line-height: 1.15;
    margin-top: 6px;
}

.month-totals {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.month-totals div {
    background: var(--surface-soft);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
}

.month-totals strong {
    display: block;
    font-size: 20px;
    margin-top: 5px;
}

.usage-panel {
    margin-bottom: 18px;
}

.usage-summary strong {
    display: block;
    font-size: 24px;
    line-height: 1.15;
}

.usage-summary span {
    color: var(--muted);
    display: block;
    font-weight: 700;
    margin-top: 4px;
}

.usage-meter {
    background: #eef2f6;
    border-radius: 999px;
    height: 10px;
    margin-top: 10px;
    overflow: hidden;
}

.usage-meter span {
    background: var(--primary);
    display: block;
    height: 100%;
    margin: 0;
    min-width: 0;
}

.usage-page-grid {
    align-items: stretch;
    display: grid;
    gap: 18px;
    grid-template-columns: minmax(260px, 1fr) minmax(320px, 1.2fr);
}

.usage-facts {
    display: grid;
    gap: 10px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.usage-facts div {
    background: var(--surface-soft);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
}

.usage-facts span {
    color: var(--muted);
    display: block;
    font-size: 13px;
    font-weight: 700;
}

.usage-facts strong {
    display: block;
    font-size: 18px;
    margin-top: 5px;
}

.alert {
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 18px;
    padding: 12px 14px;
}

.alert.success {
    background: #ecfdf3;
    border-color: #abefc6;
    color: #05603a;
}

.alert.error {
    background: #fef3f2;
    border-color: #fecdca;
    color: #912018;
}

.alert.warning {
    background: #fffaeb;
    border-color: #fedf89;
    color: #93370d;
}

.code-block {
    background: #1f2933;
    border-radius: 8px;
    color: #f5f7fa;
    overflow: auto;
    padding: 12px;
    white-space: pre-wrap;
}

.form-grid {
    display: grid;
    gap: 16px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.form-grid.two {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.field {
    min-width: 0;
}

.field.full {
    grid-column: 1 / -1;
}

label {
    color: #344054;
    display: block;
    font-weight: 700;
    margin: 0 0 6px;
}

.field-help {
    color: var(--muted);
    font-size: 0.88rem;
    line-height: 1.4;
    margin: 6px 0 0;
}

input,
select,
textarea {
    background: #fff;
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    color: var(--text);
    font: inherit;
    min-height: 38px;
    padding: 8px 10px;
    width: 100%;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary);
    outline: 3px solid #ccfbef;
}

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

.form-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin: 18px 0;
}

.filters-panel {
    margin-bottom: 18px;
}

.filters-form {
    align-items: end;
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(6, minmax(0, 1fr));
}

.filters-form .search-field {
    grid-column: span 2;
}

.filters-actions {
    display: flex;
    grid-column: 1 / -1;
    justify-content: flex-end;
    margin-top: 4px;
    padding-top: 10px;
}

.login-card .form-actions {
    margin-bottom: 0;
}

.line-button {
    align-items: center;
    border-radius: 6px;
    display: inline-flex;
    justify-content: center;
    min-height: 32px;
    min-width: 32px;
    padding: 6px 9px;
}

.table-wrap {
    overflow-x: auto;
}

.data-table {
    border-collapse: collapse;
    min-width: 960px;
    width: 100%;
}

.data-table.compact-table {
    min-width: 640px;
}

.data-table th,
.data-table td {
    border-bottom: 1px solid var(--border);
    padding: 11px 12px;
    text-align: left;
    vertical-align: top;
}

.data-table th {
    background: var(--surface-soft);
    color: #344054;
    font-size: 12px;
    text-transform: uppercase;
}

.data-table tr:last-child td {
    border-bottom: 0;
}

.data-table tbody tr:hover {
    background: #fbfcfd;
}

.invoice-lines th:nth-child(1),
.invoice-lines td:nth-child(1) {
    min-width: 112px;
    width: 112px;
}

.invoice-lines th:nth-child(2),
.invoice-lines td:nth-child(2) {
    min-width: 190px;
    width: 190px;
}

.invoice-lines th:nth-child(3),
.invoice-lines td:nth-child(3) {
    min-width: 240px;
}

.invoice-lines th:nth-child(4),
.invoice-lines td:nth-child(4) {
    min-width: 96px;
    width: 96px;
}

.invoice-lines th:nth-child(5),
.invoice-lines td:nth-child(5) {
    min-width: 86px;
    width: 86px;
}

.invoice-lines th:nth-child(6),
.invoice-lines td:nth-child(6),
.invoice-lines th:nth-child(8),
.invoice-lines td:nth-child(8) {
    min-width: 112px;
    width: 112px;
}

.invoice-lines th:nth-child(7),
.invoice-lines td:nth-child(7) {
    min-width: 92px;
    width: 92px;
}

.invoice-lines th:nth-child(9),
.invoice-lines td:nth-child(9) {
    min-width: 88px;
    width: 88px;
}

.invoice-lines th:nth-child(10),
.invoice-lines td:nth-child(10) {
    min-width: 48px;
    width: 48px;
}

.invoice-lines input,
.invoice-lines select {
    min-width: 0;
}

.right {
    text-align: right !important;
}

.muted {
    color: var(--muted);
}

.strong-link {
    font-weight: 700;
}

.badge {
    border-radius: 999px;
    display: inline-flex;
    font-size: 12px;
    font-weight: 700;
    line-height: 1;
    padding: 5px 8px;
    text-transform: uppercase;
}

.badge.draft {
    background: #eff8ff;
    color: var(--info);
}

.badge.pending {
    background: #fffaeb;
    color: var(--warning);
}

.badge.failed {
    background: #fef3f2;
    color: var(--danger);
}

.badge.sent {
    background: #ecfdf3;
    color: var(--success);
}

.badge.cancelled {
    background: #f2f4f7;
    color: #475467;
}

.empty-state {
    color: var(--muted);
    padding: 36px 20px;
    text-align: center;
}

@media (max-width: 1100px) {
    .app-header-inner {
        align-items: center;
        display: grid;
        gap: 10px;
        grid-template-columns: 1fr auto;
        padding: 14px 18px;
    }

    .page-header {
        align-items: stretch;
        flex-direction: column;
    }

    .brand img {
        max-height: 70px;
        max-width: 220px;
    }

    .menu-toggle {
        align-items: center;
        background: var(--surface);
        border: 1px solid var(--border-strong);
        border-radius: 6px;
        color: var(--text);
        cursor: pointer;
        display: inline-flex;
        font: inherit;
        font-weight: 700;
        min-height: 36px;
        padding: 8px 12px;
    }

    .app-nav {
        display: none;
        grid-column: 1 / -1;
    }

    .app-nav.open {
        display: flex;
    }

    .app-nav,
    .user-menu {
        flex-wrap: wrap;
    }

    .user-menu {
        grid-column: 1 / -1;
        justify-content: flex-start;
    }

    .app-main {
        padding: 18px;
    }

    .page-actions {
        justify-content: flex-start;
    }

    .detail-grid,
    .dashboard-grid,
    .month-totals,
    .summary-grid,
    .usage-page-grid,
    .usage-facts,
    .filters-form,
    .form-grid,
    .form-grid.two {
        grid-template-columns: 1fr;
    }

    .filters-form .search-field {
        grid-column: auto;
    }

    .detail-list div {
        grid-template-columns: 1fr;
    }
}
