:root,
[data-theme="light"] {
    --bg: #f4f6fb;
    --bg-elevated: #ffffff;
    --bg-card: #ffffff;
    --bg-hover: #eef2ff;
    --border: #e2e8f0;
    --text: #0f172a;
    --text-muted: #64748b;
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-soft: rgba(79, 70, 229, 0.1);
    --success: #059669;
    --warning: #d97706;
    --error: #dc2626;
    --info: #2563eb;
    --surface: #ffffff;
    --surface-muted: #f8fafc;
    --code-bg: #eef2ff;
    --code-color: #3730a3;
    --login-page-bg: linear-gradient(135deg, #f8fafc 0%, #eef2ff 50%, #f8fafc 100%);
    --login-hero-bg: radial-gradient(circle at 20% 50%, rgba(79, 70, 229, 0.12), transparent 60%);
    --modal-overlay: rgba(15, 23, 42, 0.45);
    --sidebar-shadow: 1px 0 0 rgba(15, 23, 42, 0.04);
    --elevation-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
    --sidebar-width: 280px;
    --radius: 14px;
    --radius-sm: 8px;
    --shadow: 0 12px 32px rgba(15, 23, 42, 0.08);
    --font: 'DM Sans', system-ui, sans-serif;
    --font-display: 'Instrument Serif', Georgia, serif;
}

[data-theme="dark"] {
    --bg: #0f1117;
    --bg-elevated: #171923;
    --bg-card: #1c2030;
    --bg-hover: #252a3a;
    --border: rgba(255, 255, 255, 0.08);
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --primary: #6366f1;
    --primary-hover: #818cf8;
    --primary-soft: rgba(99, 102, 241, 0.15);
    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;
    --info: #3b82f6;
    --surface: #1c2030;
    --surface-muted: #252a3a;
    --code-bg: rgba(99, 102, 241, 0.15);
    --code-color: #c7d2fe;
    --login-page-bg: linear-gradient(135deg, #0f1117 0%, #171923 50%, #0f1117 100%);
    --login-hero-bg: radial-gradient(circle at 20% 50%, rgba(99, 102, 241, 0.2), transparent 60%);
    --modal-overlay: rgba(0, 0, 0, 0.65);
    --sidebar-shadow: 1px 0 0 rgba(255, 255, 255, 0.04);
    --elevation-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
    --shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

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

code {
    font-family: 'Consolas', monospace;
    font-size: 0.875em;
    background: var(--code-bg);
    color: var(--code-color);
    padding: 0.15em 0.45em;
    border-radius: 4px;
}

/* Login Page */
.login-page {
    background: var(--login-page-bg);
}

.login-shell {
    display: grid;
    grid-template-columns: 1fr 1fr;
    min-height: 100vh;
}

.login-hero {
    display: flex;
    align-items: center;
    padding: 4rem;
    background: var(--login-hero-bg);
}

.hero-content h1 {
    font-family: var(--font-display);
    font-size: clamp(2.5rem, 4vw, 3.5rem);
    font-weight: 400;
    line-height: 1.15;
    margin: 0.75rem 0 1.25rem;
}

.hero-features {
    list-style: none;
    margin-top: 2rem;
}

.hero-features li {
    padding: 0.6rem 0;
    padding-left: 1.75rem;
    position: relative;
    color: var(--text-muted);
}

.hero-features li::before {
    content: '✓';
    position: absolute;
    left: 0;
    color: var(--success);
    font-weight: 700;
}

.login-panel {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.login-card {
    width: 100%;
    max-width: 420px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2.5rem;
    box-shadow: var(--shadow);
}

.login-card h2 {
    font-size: 1.75rem;
    margin: 1rem 0 0.25rem;
}

.demo-credentials {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
    font-size: 0.85rem;
    color: var(--text-muted);
}

.demo-credentials ul {
    list-style: none;
    margin-top: 0.5rem;
}

.demo-credentials li { padding: 0.25rem 0; }

/* App Shell */
.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-elevated);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    box-shadow: var(--sidebar-shadow);
}

.sidebar-brand {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.875rem 1rem;
    border-bottom: 1px solid var(--border);
}

.brand-lockup {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas:
        "logo title"
        ". subtitle";
    column-gap: 0.5rem;
    row-gap: 0.15rem;
    align-items: center;
    min-width: 0;
}

.brand-lockup-sidebar {
    flex: 1;
}

.brand-lockup-login {
    grid-template-areas: "logo title";
    justify-items: center;
    width: fit-content;
    margin: 0 auto 0.75rem;
}

.brand-lockup-logo {
    grid-area: logo;
    display: block;
    height: 32px;
    width: auto;
    max-width: 118px;
    object-fit: contain;
}

.brand-lockup-login .brand-lockup-logo {
    height: 36px;
    max-width: 132px;
}

.brand-lockup-title {
    grid-area: title;
    font-size: 1.35rem;
    font-weight: 700;
    line-height: 1;
    letter-spacing: -0.02em;
    color: var(--text);
}

.brand-lockup-subtitle {
    grid-area: subtitle;
    margin: 0;
    font-size: 0.875rem;
    font-weight: 400;
    line-height: 1.2;
    color: var(--text-muted);
}

.sidebar-close-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    margin-left: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-muted);
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    flex-shrink: 0;
}

.sidebar-close-btn:hover {
    background: var(--bg-hover);
    color: var(--text);
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--modal-overlay);
    z-index: 90;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.sidebar-nav {
    flex: 1;
    min-height: 0;
    padding: 0.625rem 0.5rem;
    overflow-y: auto;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.875rem;
    line-height: 1.25;
    transition: all 0.15s ease;
    text-decoration: none;
}

.nav-link-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.125rem;
    height: 1.125rem;
    flex-shrink: 0;
    opacity: 0.8;
}

.nav-link-icon svg {
    width: 1.125rem;
    height: 1.125rem;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.nav-link-label {
    min-width: 0;
}

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

.nav-link.is-active {
    background: var(--primary-soft);
    color: var(--primary);
    font-weight: 600;
}

.nav-link.is-active .nav-link-icon {
    opacity: 1;
}

.nav-divider {
    height: 1px;
    margin: 0.4rem 0.75rem;
    background: var(--border);
}

.sidebar-footer {
    margin-top: auto;
    flex-shrink: 0;
    padding: 0.75rem;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.user-chip {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.25rem;
}

.avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--primary-soft);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.875rem;
}

.user-chip strong { display: block; font-size: 0.8125rem; }
.user-chip span { font-size: 0.7rem; color: var(--text-muted); }

.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    background: var(--bg);
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 2rem 2.5rem 1rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg-elevated);
    position: sticky;
    top: 0;
    z-index: 80;
}

.topbar-start {
    display: flex;
    align-items: flex-start;
    gap: 0.875rem;
    min-width: 0;
    flex: 1;
}

.topbar-title {
    min-width: 0;
}

.mobile-menu-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    flex-shrink: 0;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    position: relative;
    z-index: 1;
}

.mobile-menu-btn:hover {
    background: var(--bg-hover);
}

.mobile-menu-icon,
.mobile-menu-icon::before,
.mobile-menu-icon::after {
    display: block;
    width: 18px;
    height: 2px;
    background: currentColor;
    border-radius: 999px;
    position: relative;
}

.mobile-menu-icon::before,
.mobile-menu-icon::after {
    content: '';
    position: absolute;
    left: 0;
}

.mobile-menu-icon::before { top: -6px; }
.mobile-menu-icon::after { top: 6px; }

body.sidebar-open .mobile-menu-icon {
    background: transparent;
}

body.sidebar-open .mobile-menu-icon::before {
    top: 0;
    transform: rotate(45deg);
}

body.sidebar-open .mobile-menu-icon::after {
    top: 0;
    transform: rotate(-45deg);
}

.topbar h1 {
    font-size: 1.75rem;
    font-weight: 600;
    line-height: 1.2;
    overflow-wrap: anywhere;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-muted);
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.theme-toggle:hover {
    background: var(--bg-hover);
    color: var(--text);
}

.theme-toggle .theme-icon {
    width: 18px;
    height: 18px;
}

.theme-toggle .theme-icon-sun { display: none; }
.theme-toggle .theme-icon-moon { display: block; }

[data-theme="dark"] .theme-toggle .theme-icon-sun { display: block; }
[data-theme="dark"] .theme-toggle .theme-icon-moon { display: none; }

.theme-toggle-login {
    position: fixed;
    top: 1.25rem;
    right: 1.25rem;
    z-index: 200;
}

.page-content {
    padding: 1.5rem 2.5rem 3rem;
}

.eyebrow {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--primary);
    font-weight: 600;
}

.muted { color: var(--text-muted); }
.small { font-size: 0.85rem; }

/* Components */
.panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--elevation-shadow);
}

.panel.compact { padding: 1.25rem; }

.panel-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.panel-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stats-grid.compact { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--elevation-shadow);
}

.stat-label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
}

.stat-card strong {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.stat-card p {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.65rem 1.25rem;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.9rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all 0.15s ease;
    text-decoration: none;
}

.btn:hover { text-decoration: none; }

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
    color: white;
}

.btn-primary:disabled,
.btn-primary[disabled] {
    background: var(--surface-muted);
    border: 1px solid var(--border);
    color: var(--text-muted);
    cursor: not-allowed;
    opacity: 1;
}

.btn-primary:disabled:hover,
.btn-primary[disabled]:hover {
    background: var(--surface-muted);
    color: var(--text-muted);
}

.btn-outline {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
}

.btn-outline:hover {
    background: var(--bg-hover);
    color: var(--text);
}

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
}

.btn-ghost:hover {
    background: var(--bg-hover);
    color: var(--text);
}

.btn-block { width: 100%; }
.btn-sm { padding: 0.4rem 0.75rem; font-size: 0.8rem; }

.button-row {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.action-stack {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* Forms */
.form-stack {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.settings-layout {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1.25rem;
    align-items: start;
}

.settings-layout .settings-panel {
    margin: 0;
    height: 100%;
}

.settings-layout .form-stack {
    max-width: none;
}

.settings-panel-wide {
    grid-column: 1 / -1;
}

.sheet-column-list {
    margin: 0.75rem 0 0;
    padding-left: 1.1rem;
}

.sheet-column-list li + li {
    margin-top: 0.35rem;
}

.sync-result-summary {
    display: grid;
    gap: 0.35rem;
    font-size: 0.925rem;
}

.checkbox-label {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    font-size: 0.925rem;
    line-height: 1.5;
}

.checkbox-label input[type="checkbox"] {
    margin-top: 0.2rem;
}

.settings-collapse {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-muted);
    overflow: hidden;
}

.settings-collapse summary {
    cursor: pointer;
    font-weight: 600;
    font-size: 0.875rem;
    padding: 0.875rem 1rem;
    list-style: none;
    color: var(--text);
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

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

.settings-collapse summary::after {
    content: '+';
    font-size: 1.1rem;
    line-height: 1;
    color: var(--primary);
    font-weight: 700;
}

.settings-collapse[open] summary::after {
    content: '−';
}

.settings-collapse summary:hover {
    background: var(--bg-hover);
}

.settings-collapse-body {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 1rem;
    border-top: 1px solid var(--border);
}

.payment-schedule-fields.is-hidden {
    display: none;
}

.payment-schedule-fields .form-grid {
    margin-top: 0.25rem;
}

.payment-date-picker-label {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.payment-date-picker {
    width: 100%;
    max-width: 280px;
}

.settings-subsection-form {
    padding-top: 1.25rem;
    border-top: 1px solid var(--border);
}

.settings-subsection-form:first-of-type {
    padding-top: 0;
    border-top: 0;
}

.settings-subsection-title {
    margin: 0 0 0.5rem;
    font-size: 1rem;
}

.settings-subsection-form .settings-subsection-title {
    margin-top: 0.25rem;
}

.settings-subsection-form + .settings-subsection-form {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
}

.panel-settings.settings-layout {
    gap: 0.75rem;
}

.panel-settings .settings-panel {
    padding: 1rem 1.125rem;
}

.panel-settings .panel-header {
    margin-bottom: 0.75rem;
    gap: 0.75rem;
}

.panel-settings .panel-header h2 {
    font-size: 1.05rem;
    line-height: 1.3;
}

.panel-settings .panel-header .muted {
    font-size: 0.82rem;
    margin-top: 0.15rem;
    line-height: 1.4;
}

.panel-settings .form-stack {
    gap: 0.75rem;
}

.panel-settings label span {
    font-size: 0.72rem;
    margin-bottom: 0.3rem;
}

.panel-settings input,
.panel-settings select,
.panel-settings textarea {
    padding: 0.55rem 0.7rem;
    font-size: 0.9rem;
}

.panel-settings textarea {
    min-height: 5.5rem;
}

.panel-settings .settings-subsection-form {
    padding-top: 0.875rem;
}

.panel-settings .settings-subsection-form + .settings-subsection-form {
    margin-top: 1rem;
    padding-top: 1rem;
}

.panel-settings .settings-subsection-title {
    font-size: 0.88rem;
    margin-bottom: 0.35rem;
}

.panel-settings .settings-collapse summary {
    padding: 0.65rem 0.875rem;
    font-size: 0.8rem;
}

.panel-settings .settings-collapse-body {
    padding: 0.75rem;
    gap: 0.75rem;
}

.panel-settings .table-wrap table {
    font-size: 0.82rem;
}

.panel-settings th {
    padding: 0.55rem 0.75rem;
    font-size: 0.68rem;
}

.panel-settings td {
    padding: 0.5rem 0.75rem;
}

.panel-settings .form-grid {
    gap: 0.75rem;
}

.panel-settings .checkbox-label {
    font-size: 0.85rem;
    gap: 0.5rem;
}

.panel-settings .readonly-field p {
    margin: 0.15rem 0;
    font-size: 0.9rem;
}

.panel-settings .sync-result-summary {
    font-size: 0.85rem;
    gap: 0.25rem;
}

.panel-settings .sheet-column-list {
    font-size: 0.85rem;
    margin-top: 0.5rem;
}

.panel-settings .button-row .btn {
    padding: 0.5rem 0.9rem;
    font-size: 0.85rem;
}

.panel-settings .muted.small {
    font-size: 0.78rem;
    line-height: 1.4;
}

.payment-date-picker-help {
    margin-top: 0.5rem;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

.form-grid .full-width { grid-column: 1 / -1; }

label span {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 0.4rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="month"],
input[type="file"],
select,
textarea {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: var(--font);
    font-size: 0.925rem;
    transition: border-color 0.15s ease;
}

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

.checkbox-card {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.875rem;
    background: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    margin-bottom: 0.5rem;
}

.checkbox-card input { margin-top: 0.2rem; }
.checkbox-card span { font-size: 0.875rem; }

.inline-form {
    display: flex;
    align-items: flex-end;
    gap: 0.75rem;
    flex-wrap: wrap;
}

/* Tables */
.table-wrap {
    overflow-x: auto;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface);
}

.table-wrap:has(+ .table-footer) {
    border-bottom: none;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

th {
    background: var(--surface-muted);
    text-align: left;
    padding: 0.875rem 1rem;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    font-weight: 600;
    white-space: nowrap;
}

.sortable-th {
    padding: 0;
}

.sortable-th-link {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    width: 100%;
    min-height: 100%;
    padding: 0.875rem 1rem;
    color: inherit;
    text-decoration: none;
    font: inherit;
    letter-spacing: inherit;
    text-transform: inherit;
    background: transparent;
    border: none;
    cursor: pointer;
}

.sortable-th-link:hover {
    color: var(--text);
    text-decoration: none;
}

.sortable-th-link::after {
    content: '↕';
    font-size: 0.7rem;
    opacity: 0.45;
}

.sortable-th.is-sorted.is-sorted-asc .sortable-th-link::after {
    content: '↑';
    opacity: 1;
    color: var(--primary);
}

.sortable-th.is-sorted.is-sorted-desc .sortable-th-link::after {
    content: '↓';
    opacity: 1;
    color: var(--primary);
}

th.text-right .sortable-th-link,
.sortable-th.text-right .sortable-th-link {
    justify-content: flex-end;
}

td {
    padding: 0.875rem 1rem;
    border-top: 1px solid var(--border);
    vertical-align: middle;
    background: var(--surface);
}

tr:hover td { background: var(--surface-muted); }

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

.datetime-stacked {
    display: inline-block;
    line-height: 1.35;
    white-space: normal;
}

/* Compact status cells in tables */
table td:has(> .badge) {
    width: 1%;
    white-space: nowrap;
}

/* Table action columns */
th.actions-col,
td.actions,
table td:has(> .btn),
table td:has(> a.btn),
table td:has(> button.btn) {
    width: 1%;
    white-space: nowrap;
    padding-left: 0.5rem;
    padding-right: 0.5rem;
    vertical-align: middle;
}

.actions {
    white-space: nowrap;
    vertical-align: middle;
}

/* Compact buttons in tables */
table .btn-sm {
    padding: 0.3rem 0.5rem;
    font-size: 0.75rem;
}

.actions > .btn,
.actions > button,
.actions > .inline-form {
    vertical-align: middle;
}

.actions > .btn + .btn,
.actions > button + button,
.actions > .inline-form + .btn,
.actions > .btn + .inline-form,
.actions > .inline-form + .inline-form,
.actions > button + .inline-form,
.actions > .inline-form + button {
    margin-left: 0.25rem;
}

.actions .inline-form {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    margin: 0;
    flex-wrap: nowrap;
}

/* Mobile card tables */
@media (max-width: 1024px) {
    .table-mobile-cards.table-wrap {
        overflow-x: visible;
        border: none;
        background: transparent;
    }

    .table-mobile-cards table {
        display: block;
        border: none;
        font-size: 0.875rem;
    }

    .table-mobile-cards thead {
        display: none;
    }

    .table-mobile-cards tbody {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
    }

    .table-mobile-cards tbody tr {
        display: block;
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--radius-sm);
        padding: 0.875rem 1rem;
        box-shadow: var(--elevation-shadow);
    }

    .table-mobile-cards tbody tr:hover td {
        background: transparent;
    }

    .table-mobile-cards td {
        display: flex;
        align-items: flex-start;
        justify-content: space-between;
        gap: 0.75rem;
        padding: 0.35rem 0;
        border: none;
        background: transparent !important;
        white-space: normal;
        width: auto !important;
        text-align: right;
    }

    .table-mobile-cards td::before {
        content: attr(data-label);
        flex: 0 0 42%;
        max-width: 9.5rem;
        font-size: 0.7rem;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        color: var(--text-muted);
        line-height: 1.35;
        text-align: left;
    }

    .table-mobile-cards td.actions {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
        margin-top: 0.35rem;
        padding-top: 0.65rem;
        border-top: 1px solid var(--border);
    }

    .table-mobile-cards td.actions::before {
        content: none;
    }

    .table-mobile-cards td.actions .table-card-actions {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
        width: 100%;
    }

    .table-mobile-cards td.actions .btn,
    .table-mobile-cards td.actions .inline-form .btn,
    .table-mobile-cards td.actions .table-card-actions .btn {
        width: 100%;
        margin: 0 !important;
    }

    .table-mobile-cards td.actions .inline-form {
        display: flex;
        flex-direction: column;
        width: 100%;
        gap: 0.5rem;
    }

    .table-mobile-cards .btn-sm {
        min-height: 44px;
        font-size: 0.85rem;
        padding: 0.5rem 0.75rem;
    }

    .table-mobile-cards.invoice-breakdown-wrap .invoice-total-bar {
        justify-content: space-between;
        margin-top: 0.25rem;
        border: 1px solid var(--border);
        border-radius: var(--radius-sm);
    }

    .portal-admin .panel-header-actions {
        width: 100%;
    }

    .portal-admin .panel-header-actions.button-row,
    .portal-admin .panel-header-actions .inline-form {
        flex-direction: column;
        align-items: stretch;
    }

    .portal-admin .panel-header-actions .btn,
    .portal-admin .panel-header-actions .inline-form input,
    .portal-admin .panel-header-actions .inline-form select {
        width: 100%;
    }

    .portal-admin .panel .inline-form {
        flex-direction: column;
        align-items: stretch;
        width: 100%;
    }

    .portal-admin .panel .inline-form .btn,
    .portal-admin .panel .inline-form input,
    .portal-admin .panel .inline-form select {
        width: 100%;
    }
}

#pdfModalApprove.hidden,
#pdfModalReject.hidden,
#pdfModalDownload.hidden {
    display: none;
}

.table-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.875rem 1rem;
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
    background: var(--surface-muted);
    font-size: 0.875rem;
}

.pagination-info {
    color: var(--text-muted);
}

.pagination {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    margin-left: auto;
}

.pagination-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2rem;
    height: 2rem;
    padding: 0 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-size: 0.85rem;
    font-weight: 600;
    text-decoration: none;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.pagination-btn:hover {
    background: var(--bg-hover);
    color: var(--text);
    text-decoration: none;
}

.pagination-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #ffffff;
}

.pagination-btn.disabled {
    opacity: 0.45;
    cursor: default;
}

.pagination-ellipsis {
    color: var(--text-muted);
    padding: 0 0.25rem;
}

/* Badges */
.badge {
    display: inline-block;
    padding: 0.15rem 0.45rem;
    border-radius: 999px;
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    line-height: 1.25;
    width: fit-content;
    max-width: 100%;
    white-space: nowrap;
    flex-shrink: 0;
}

.panel-header .badge {
    align-self: flex-start;
}

.panel-header-actions .badge,
.button-row .badge {
    align-self: center;
}

.badge-draft { background: #f1f5f9; color: #64748b; }
.badge-pending { background: #fef3c7; color: #b45309; }
.badge-ready { background: #dbeafe; color: #1d4ed8; }
.badge-submitted { background: #e0e7ff; color: #4338ca; }
.badge-received { background: #d1fae5; color: #047857; }
.badge-paid { background: #dbeafe; color: #1d4ed8; }
.badge-rejected { background: #fee2e2; color: #b91c1c; }

[data-theme="dark"] .badge-draft { background: rgba(148, 163, 184, 0.18); color: #cbd5e1; }
[data-theme="dark"] .badge-pending { background: rgba(245, 158, 11, 0.18); color: #fbbf24; }
[data-theme="dark"] .badge-ready { background: rgba(59, 130, 246, 0.18); color: #93c5fd; }
[data-theme="dark"] .badge-submitted { background: rgba(99, 102, 241, 0.2); color: #a5b4fc; }
[data-theme="dark"] .badge-received { background: rgba(16, 185, 129, 0.18); color: #6ee7b7; }
[data-theme="dark"] .badge-paid { background: rgba(59, 130, 246, 0.18); color: #93c5fd; }
[data-theme="dark"] .badge-rejected { background: rgba(239, 68, 68, 0.18); color: #fca5a5; }

[data-theme="dark"] .alert-success { background: rgba(16, 185, 129, 0.12); border-color: rgba(16, 185, 129, 0.35); color: #6ee7b7; }
[data-theme="dark"] .alert-error { background: rgba(239, 68, 68, 0.12); border-color: rgba(239, 68, 68, 0.35); color: #fca5a5; }
[data-theme="dark"] .alert-warning { background: rgba(245, 158, 11, 0.12); border-color: rgba(245, 158, 11, 0.35); color: #fcd34d; }
[data-theme="dark"] .alert-info { background: rgba(59, 130, 246, 0.12); border-color: rgba(59, 130, 246, 0.35); color: #93c5fd; }

/* Alerts */
.alert {
    padding: 1rem 1.25rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
    font-size: 0.9rem;
    border: 1px solid;
}

.alert ul { margin: 0.5rem 0 0 1.25rem; }

.alert-success { background: #ecfdf5; border-color: #a7f3d0; color: #047857; }
.alert-error { background: #fef2f2; border-color: #fecaca; color: #b91c1c; }
.alert-warning { background: #fffbeb; border-color: #fde68a; color: #b45309; }
.alert-info { background: #eff6ff; border-color: #bfdbfe; color: #1d4ed8; }

.dashboard-dates-announcement {
    margin-bottom: 1.25rem;
}

.dashboard-dates-announcement strong {
    display: inline;
}

@media (max-width: 768px) {
    .dashboard-dates-announcement {
        font-size: 0.875rem;
        line-height: 1.45;
    }
}

/* Invoice Layout */
.invoice-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
    align-items: start;
}

.invoice-document { margin-bottom: 0; }

.invoice-header {
    display: flex;
    justify-content: space-between;
    gap: 1.5rem;
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
}

.invoice-header h2 {
    font-family: var(--font-display);
    font-size: 1.75rem;
    font-weight: 400;
    margin: 0.25rem 0 0.75rem;
}

.invoice-meta div {
    text-align: right;
    margin-bottom: 0.5rem;
}

.invoice-meta span {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

.invoice-parties {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    margin-bottom: 2rem;
}

.party-block h3 {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--primary);
    margin-bottom: 0.75rem;
}

.readonly-field {
    font-size: 0.925rem;
    line-height: 1.6;
    margin-bottom: 0.25rem;
}

.field-note {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-style: italic;
    margin-top: 0.5rem;
}

.line-items tfoot td { font-size: 1.1rem; }

.invoice-breakdown-wrap.table-wrap {
    overflow: hidden;
}

.invoice-breakdown-wrap .invoice-total-bar {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 1rem;
    width: 100%;
    padding: 0.875rem 1rem;
    background: var(--surface-muted);
    border-top: 1px solid var(--border);
    font-size: 1.1rem;
}

.invoice-total-bar strong {
    font-size: 1rem;
}

.invoice-total-bar .total-amount {
    font-size: 1.1rem;
    text-align: right;
}

.total-amount { color: var(--success); }

.payment-block, .signature-block {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
}

.invoice-preview-card {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
}

.preview-row span {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 0.25rem;
}

.confidential {
    color: var(--text-muted);
    font-style: italic;
}

.invoice-sidebar {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.invoice-actions {
    margin-top: 2rem;
    padding: 1.25rem 1.5rem;
    border: 1px solid rgba(79, 70, 229, 0.12);
    border-left: 4px solid var(--primary);
    border-radius: var(--radius-sm);
    background: var(--primary-soft);
}

[data-theme="dark"] .invoice-actions {
    border-color: rgba(99, 102, 241, 0.2);
}

.invoice-actions h3 {
    font-size: 1.1rem;
    margin-bottom: 1rem;
}

.invoice-actions .button-row {
    align-items: center;
    justify-content: center;
}

.invoice-actions .button-row .btn {
    align-self: center;
}

.invoice-actions .invoice-confirm-checkbox {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
    align-self: center;
    column-gap: 0.625rem;
    flex: 0 1 auto;
    margin: 0;
    max-width: 100%;
    cursor: pointer;
}

.invoice-actions .invoice-confirm-checkbox input[type="checkbox"] {
    margin: 0;
    width: 1rem;
    height: 1rem;
    accent-color: var(--primary);
    justify-self: center;
    align-self: center;
}

.invoice-actions .invoice-confirm-checkbox span {
    font-size: 0.875rem;
    line-height: 1rem;
    padding-top: 0.25rem;
    color: var(--primary);
    font-weight: 500;
}

.invoice-submit-form {
    display: contents;
}

.modal-content.submit-modal {
    --submit-header-bg: #2563eb;
    --submit-btn-bg: #1e40af;
    --submit-btn-hover: #1e3a8a;
    --submit-btn-disabled: #93c5fd;
    padding: 0;
    overflow: hidden;
    border: none;
    border-radius: 14px;
    max-width: 460px;
    box-shadow: 0 18px 40px rgba(15, 23, 42, 0.18);
}

.modal-content.submit-modal.submit-modal-reject {
    --submit-header-bg: #b91c1c;
}

.modal-content.submit-modal .submit-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    width: 100%;
    box-sizing: border-box;
    background: var(--submit-header-bg);
    color: #fff;
    padding: 1.125rem 1.25rem;
    border-radius: 14px 14px 0 0;
}

.modal-content.submit-modal .submit-modal-title {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    min-width: 0;
}

.modal-content.submit-modal .submit-modal-title-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.modal-content.submit-modal .submit-modal-header h3 {
    margin: 0;
    color: #fff;
    font-size: 1.125rem;
    font-weight: 700;
}

.modal-content.submit-modal .submit-modal-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border: none;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.18);
    color: #fff;
    font-size: 1.35rem;
    line-height: 1;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s ease, transform 0.25s ease;
}

.modal-content.submit-modal .submit-modal-close:hover {
    background: rgba(255, 255, 255, 0.28);
    transform: rotate(90deg);
}

.modal-content.submit-modal .submit-modal-body {
    padding: 1.5rem 1.25rem 1.25rem;
}

.modal-content.submit-modal .submit-modal-message {
    margin: 0 0 0.75rem;
    line-height: 1.65;
    color: var(--text);
    font-size: 0.95rem;
}

.modal-content.submit-modal .submit-modal-message:last-of-type {
    margin-bottom: 1.5rem;
}

.modal-content.submit-modal .btn-submit-modal {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.65rem 1.25rem;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--submit-btn-bg);
    color: #fff;
    font-family: var(--font);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease;
}

.modal-content.submit-modal .btn-submit-modal-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.modal-content.submit-modal .btn-submit-modal:hover:not(:disabled) {
    background: var(--submit-btn-hover);
    color: #fff;
}

.modal-content.submit-modal .btn-submit-modal:disabled,
.modal-content.submit-modal .btn-submit-modal[disabled] {
    background: var(--submit-btn-disabled);
    color: rgba(255, 255, 255, 0.92);
    cursor: not-allowed;
    opacity: 1;
}

.modal-content.submit-modal .btn-submit-modal:disabled:hover,
.modal-content.submit-modal .btn-submit-modal[disabled]:hover {
    background: var(--submit-btn-disabled);
    color: rgba(255, 255, 255, 0.92);
}

.modal-content.submit-modal .btn-reject-modal {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 0.65rem 1.25rem;
    border: none;
    border-radius: var(--radius-sm);
    background: #b91c1c;
    color: #fff;
    font-family: var(--font);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease;
}

.modal-content.submit-modal .btn-reject-modal:hover {
    background: #991b1b;
    color: #fff;
}

.invoice-actions-notice {
    margin-bottom: 1.25rem;
    padding: 1rem 1.125rem;
    border: 2px solid #f59e0b;
    border-radius: var(--radius-sm);
    background: #fffbeb;
    color: #92400e;
}

.invoice-actions-notice ul {
    margin: 0;
    padding-left: 1.25rem;
}

.invoice-actions-notice li + li {
    margin-top: 0.35rem;
}

[data-theme="dark"] .invoice-actions-notice {
    background: rgba(245, 158, 11, 0.12);
    border-color: rgba(245, 158, 11, 0.55);
    color: #fcd34d;
}

.invoice-actions-alert {
    flex: 1 1 100%;
    margin-bottom: 0;
}

.list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border);
}

.list-item span { display: block; font-size: 0.85rem; color: var(--text-muted); }

/* Profile */
.profile-grid {
    display: grid;
    gap: 1rem;
}

.panel-profile .panel-header {
    margin-bottom: 0.875rem;
}

.panel-profile .panel-header h2 {
    font-size: 1.125rem;
}

.panel-profile .panel-header .muted {
    font-size: 0.85rem;
}

.profile-summary {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 0.875rem;
    margin-bottom: 0.875rem;
    background: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.profile-summary-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--primary-soft);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    font-weight: 700;
    flex-shrink: 0;
}

.profile-summary-body {
    min-width: 0;
}

.profile-summary-body h3 {
    font-size: 1.05rem;
    margin-bottom: 0.1rem;
    line-height: 1.25;
}

.profile-summary-body p {
    margin: 0;
    font-size: 0.85rem;
}

.profile-groups {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
}

.profile-group {
    background: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.75rem 0.875rem;
}

.profile-group-wide {
    grid-column: 1 / -1;
}

.profile-group-header {
    margin-bottom: 0.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.profile-group-header h3 {
    font-size: 0.8rem;
    font-weight: 600;
    margin: 0;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
}

.profile-fields {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    margin: 0;
}

.profile-fields-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.45rem 0.875rem;
}

.profile-group-wide .profile-fields-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.profile-field {
    display: grid;
    grid-template-columns: minmax(5.5rem, 38%) 1fr;
    gap: 0.35rem 0.5rem;
    align-items: baseline;
}

.profile-fields-grid .profile-field {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.profile-field dt {
    font-size: 0.68rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 600;
    line-height: 1.2;
}

.profile-field dd {
    margin: 0;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text);
    overflow-wrap: anywhere;
    line-height: 1.3;
}

.profile-alert {
    margin-top: 0.75rem;
    padding: 0.65rem 0.875rem;
    font-size: 0.875rem;
}

.profile-section h3 {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--primary);
    margin-bottom: 1rem;
}

.readonly-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.readonly-grid span {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 0.25rem;
}

@media (max-width: 768px) {
    .profile-summary {
        flex-direction: row;
        align-items: center;
        text-align: left;
    }

    .profile-groups,
    .profile-fields-grid,
    .profile-group-wide .profile-fields-grid {
        grid-template-columns: 1fr;
    }
}

/* Approval Cards */
.approval-card {
    background: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 1.25rem;
    margin-bottom: 1rem;
}

.approval-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.approval-header span {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.approval-body p { margin-bottom: 0.35rem; font-size: 0.9rem; }

.approval-form { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--border); }

.notification-item {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 1rem;
    border-bottom: 1px solid var(--border);
}

.notification-item.unread {
    background: var(--primary-soft);
    border-left: 3px solid var(--primary);
}

.notification-item p { font-size: 0.875rem; color: var(--text-muted); margin: 0.25rem 0; }
.notification-item small { font-size: 0.75rem; color: var(--text-muted); }

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    background: var(--modal-overlay);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
}

.modal.hidden { display: none; }

.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow);
}

.modal-content h3 { margin-bottom: 1.25rem; }

.modal-content-wide {
    max-width: min(860px, 94vw);
    width: min(860px, 94vw);
    height: min(90vh, calc(100vh - 2rem));
    max-height: calc(100vh - 2rem);
    padding: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.pdf-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
}

.pdf-modal-header h3 {
    margin: 0;
    font-size: 1.1rem;
}

.pdf-modal-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

.pdf-modal-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    background: #ececec;
}

.pdf-modal-frame {
    display: block;
    width: 100%;
    height: 100%;
    border: none;
    background: #ffffff;
    overflow: hidden;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--text-muted);
}

.empty-state h3 {
    color: var(--text);
    margin-bottom: 0.5rem;
}

.empty-state .btn { margin-top: 1rem; }

/* Responsive */
@media (max-width: 1024px) {
    .invoice-layout { grid-template-columns: 1fr; }
    .login-shell { grid-template-columns: 1fr; }
    .login-hero { display: none; }

    .mobile-menu-btn,
    .sidebar-close-btn {
        display: inline-flex;
    }

    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        z-index: 200;
        box-shadow: var(--shadow);
    }

    body.sidebar-open .sidebar {
        transform: translateX(0);
    }

    body.sidebar-open .sidebar-backdrop {
        display: block;
        opacity: 1;
        pointer-events: auto;
    }

    .main-content {
        margin-left: 0;
    }

    .topbar,
    .page-content {
        padding-left: 1.25rem;
        padding-right: 1.25rem;
    }

    .topbar {
        padding-top: max(1.25rem, env(safe-area-inset-top, 0px));
    }

    .sidebar {
        padding-left: env(safe-area-inset-left, 0px);
    }

    .page-content {
        padding-bottom: max(2rem, env(safe-area-inset-bottom, 0px));
    }

    .table-wrap {
        -webkit-overflow-scrolling: touch;
    }

    .topbar h1 {
        font-size: 1.45rem;
    }

    .panel {
        padding: 1.25rem;
    }

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

    .panel-header .btn,
    .panel-header .inline-form,
    .panel-header form {
        width: 100%;
    }

    .inline-form input,
    .inline-form select {
        flex: 1;
        min-width: 0;
    }
}

@media (max-width: 768px) {
    .topbar {
        flex-wrap: wrap;
        align-items: flex-start;
    }

    .topbar-actions {
        width: 100%;
        justify-content: flex-end;
    }

    .topbar h1 {
        font-size: 1.25rem;
    }

    .page-content {
        padding-bottom: 2rem;
    }

    .invoice-parties { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: 1fr; }
    .settings-layout { grid-template-columns: 1fr; }

    .invoice-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
        margin-bottom: 1.25rem;
        padding-bottom: 1rem;
    }

    .invoice-header h2 {
        font-size: 1.35rem;
    }

    .invoice-meta {
        width: 100%;
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.65rem 1rem;
    }

    .invoice-meta div {
        text-align: left;
        margin-bottom: 0;
    }

    .invoice-actions .button-row {
        flex-direction: column;
        align-items: stretch;
    }

    .invoice-actions .button-row .btn {
        width: 100%;
        align-self: stretch;
    }

    .invoice-actions .invoice-confirm-checkbox {
        align-self: stretch;
        width: 100%;
    }

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

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

    .table-footer {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }

    .pagination {
        justify-content: center;
        margin-left: 0;
        flex-wrap: wrap;
    }

    .pagination-info {
        text-align: center;
    }

    .notification-item {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }

    .notification-item .btn {
        align-self: flex-start;
    }

    .button-row {
        flex-direction: column;
    }

    .button-row .btn {
        width: 100%;
    }

    .button-row .badge {
        align-self: flex-start;
    }

    .nav-link {
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    .btn {
        min-height: 44px;
    }

    .btn-sm {
        min-height: 38px;
    }

    .modal {
        padding: 0.75rem;
    }

    .modal-content {
        padding: 1.5rem;
    }

    .modal-content-wide {
        width: 100%;
        max-width: 100%;
        height: min(92vh, calc(100vh - 1.5rem));
        max-height: calc(100vh - 1.5rem);
    }

    #pdfModal:not(.hidden) {
        padding: 0;
        align-items: stretch;
    }

    #pdfModal:not(.hidden) .modal-content-wide {
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
        border-left: none;
        border-right: none;
    }

    .pdf-modal-actions {
        flex-wrap: wrap;
        justify-content: flex-end;
        width: 100%;
    }

    .pdf-modal-actions .btn {
        min-height: 44px;
        flex: 1 1 calc(50% - 0.25rem);
    }

    .pdf-modal-header {
        flex-wrap: wrap;
        padding: 0.875rem 1rem;
    }

    .pdf-modal-header h3 {
        font-size: 1rem;
        flex: 1;
        min-width: 0;
    }

    .approval-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .login-panel {
        padding: 1.25rem;
        align-items: flex-start;
        padding-top: 4.5rem;
    }

    .login-card {
        padding: 1.5rem;
    }
}

@media (max-width: 480px) {
    .stats-grid,
    .stats-grid.compact {
        grid-template-columns: 1fr;
    }

    .invoice-meta {
        grid-template-columns: 1fr;
    }

    .table-mobile-cards td[data-label="Reason"],
    .table-mobile-cards td[data-label="Service Description"],
    .table-mobile-cards td[data-label="Comment"],
    .table-mobile-cards td[data-label="Details"] {
        flex-direction: column;
        align-items: stretch;
        text-align: left;
        gap: 0.25rem;
    }

    .topbar h1 {
        font-size: 1.125rem;
    }

    .panel-header .btn-block,
    .panel-header > a.btn {
        width: 100%;
    }

    .actions {
        white-space: normal;
    }

    .table-mobile-cards td.actions .table-card-actions .btn,
    .table-mobile-cards td.actions .btn {
        width: 100%;
        margin-top: 0 !important;
    }
}

@media print {
    .sidebar, .topbar, .invoice-sidebar, .no-print { display: none !important; }
    .main-content { margin-left: 0; }
    body { background: white; color: black; }
}
