:root {
    --navy-950: #071332;
    --navy-900: #0a1c45;
    --navy-800: #102a63;
    --blue-600: #2357d6;
    --blue-500: #356ce8;
    --teal-500: #18a69a;
    --amber-500: #e9a72e;
    --ink: #172038;
    --muted: #6f7890;
    --line: #e4e8f1;
    --surface: #ffffff;
    --background: #f4f6fa;
    --shadow: 0 18px 50px rgba(20, 38, 78, .08);
    --radius: 18px;
}

* { box-sizing: border-box; }
html { font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: var(--ink); background: var(--background); }
body { margin: 0; min-height: 100vh; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 260px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 28px 20px 20px; display: flex; flex-direction: column; color: #fff; background: linear-gradient(180deg, var(--navy-950), var(--navy-900) 70%, #0b2457); z-index: 20; }
.sidebar::after { content: ""; position: absolute; inset: auto 0 0; height: 180px; pointer-events: none; background: radial-gradient(circle at 50% 100%, rgba(53,108,232,.25), transparent 68%); }
.brand { display: flex; align-items: center; gap: 12px; margin: 0 8px 35px; position: relative; z-index: 1; }
.brand img { width: 112px; height: auto; padding: 7px 9px; border-radius: 11px; background: white; }
.brand span { font-size: 12px; line-height: 1.2; font-weight: 700; color: #b9c5df; max-width: 68px; }
.main-nav { display: grid; gap: 7px; position: relative; z-index: 1; }
.nav-item { display: flex; align-items: center; gap: 13px; min-height: 48px; padding: 10px 13px; border-radius: 12px; color: #b8c4de; font-weight: 650; transition: .2s ease; }
.nav-item:hover { color: #fff; background: rgba(255,255,255,.07); transform: translateX(2px); }
.nav-item.is-active { color: #fff; background: linear-gradient(135deg, rgba(53,108,232,.95), rgba(35,87,214,.72)); box-shadow: 0 10px 24px rgba(0,0,0,.18); }
.nav-icon { width: 26px; height: 26px; display: grid; place-items: center; font-size: 19px; color: #dce6ff; }
.sidebar-bottom { margin-top: auto; display: grid; gap: 14px; position: relative; z-index: 1; }
.user-card { display: grid; grid-template-columns: 38px 1fr auto; align-items: center; gap: 10px; padding: 14px 12px; border-top: 1px solid rgba(255,255,255,.1); }
.user-card strong, .user-card small { display: block; }
.user-card strong { font-size: 13px; }
.user-card small { color: #9cabc9; margin-top: 3px; text-transform: capitalize; }
.avatar { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 50%; color: #fff; background: linear-gradient(135deg, var(--blue-500), var(--teal-500)); font-weight: 800; }
.icon-button { border: 0; background: transparent; color: #aab7d2; font-size: 21px; }

.main-content { min-width: 0; }
.topbar { min-height: 112px; display: flex; align-items: center; gap: 24px; padding: 25px 38px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.88); backdrop-filter: blur(12px); }
.topbar h1 { margin: 3px 0 0; font-size: clamp(25px, 2vw, 34px); letter-spacing: -.03em; }
.eyebrow { margin: 0; color: var(--blue-600); text-transform: uppercase; letter-spacing: .12em; font-size: 11px; font-weight: 800; }
.topbar-actions { margin-left: auto; display: flex; gap: 10px; }
.mobile-menu { display: none; width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 11px; background: #fff; }
.page-content { padding: 32px 38px 50px; max-width: 1600px; margin: 0 auto; }

.button { min-height: 42px; padding: 10px 16px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid transparent; border-radius: 11px; font-weight: 750; transition: .2s ease; }
.button:hover { transform: translateY(-1px); }
.button-primary { color: #fff; background: linear-gradient(135deg, var(--blue-500), var(--blue-600)); box-shadow: 0 9px 20px rgba(35,87,214,.2); }
.button-secondary { color: var(--navy-800); background: #fff; border-color: var(--line); }
.button-large { width: 100%; min-height: 50px; }

.welcome-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 22px; }
.lead { margin: 0; color: var(--muted); font-size: 16px; }
.date-pill { padding: 8px 13px; border-radius: 99px; color: var(--navy-800); background: #e9eefb; font-size: 13px; font-weight: 750; }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 18px; }
.metric-card { min-height: 172px; padding: 22px; position: relative; overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: 0 8px 28px rgba(20,38,78,.045); }
.metric-card::after { content: ""; position: absolute; width: 110px; height: 110px; border-radius: 50%; right: -35px; top: -35px; background: currentColor; opacity: .06; }
.metric-card p { margin: 17px 0 5px; color: var(--muted); font-size: 13px; font-weight: 700; }
.metric-card strong { display: block; font-size: clamp(24px, 2vw, 32px); letter-spacing: -.04em; }
.metric-card > span { display: block; margin-top: 7px; color: var(--muted); font-size: 12px; }
.metric-icon { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 11px; color: currentColor; background: currentColor; box-shadow: inset 0 0 0 30px rgba(255,255,255,.88); font-size: 12px; font-weight: 900; }
.metric-blue { color: var(--blue-600); }
.metric-teal { color: var(--teal-500); }
.metric-amber { color: var(--amber-500); }
.metric-navy { color: var(--navy-800); }
.metric-card p, .metric-card strong, .metric-card > span { color: var(--ink); }
.metric-card p, .metric-card > span { color: var(--muted); }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.8fr) minmax(290px, .7fr); gap: 18px; margin-top: 18px; }
.panel { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); overflow: hidden; }
.panel-heading { min-height: 82px; padding: 20px 24px; display: flex; align-items: center; justify-content: space-between; gap: 20px; border-bottom: 1px solid var(--line); }
.panel-heading h2 { margin: 4px 0 0; font-size: 20px; letter-spacing: -.02em; }
.text-link { color: var(--blue-600); font-size: 13px; font-weight: 800; }
.quick-panel { align-self: start; }
.quick-action { display: grid; grid-template-columns: 42px 1fr auto; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); transition: .18s ease; }
.quick-action:hover { background: #f7f9fd; }
.quick-action strong, .quick-action small { display: block; }
.quick-action small { margin-top: 3px; color: var(--muted); }
.quick-action b { color: var(--blue-600); }
.quick-icon { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 11px; color: var(--blue-600); background: #edf2ff; font-weight: 900; }
.automation-note { margin: 18px; padding: 15px; display: grid; grid-template-columns: 12px 1fr; gap: 10px; border-radius: 13px; color: #245d58; background: #eaf8f5; }
.automation-note strong, .automation-note small { display: block; }
.automation-note small { margin-top: 4px; line-height: 1.45; }
.pulse-dot { width: 9px; height: 9px; margin-top: 4px; border-radius: 50%; background: var(--teal-500); box-shadow: 0 0 0 5px rgba(24,166,154,.12); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 14px 20px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); background: #fafbfe; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; }
td { font-size: 13px; }
.status { padding: 6px 9px; border-radius: 99px; font-size: 11px; font-weight: 800; background: #eef1f6; }
.status-paid { color: #15746c; background: #e7f7f4; }
.status-sent { color: #2357d6; background: #eaf0ff; }
.status-draft { color: #5f687b; background: #edf0f5; }
.status-payment_reminder, .status-dunning_1, .status-dunning_2, .status-dunning_3 { color: #9a5c00; background: #fff1d8; }

.empty-state { min-height: 350px; padding: 40px 20px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.empty-state.compact { min-height: 330px; }
.empty-state h3 { margin: 15px 0 7px; }
.empty-state p { max-width: 470px; margin: 0 0 20px; color: var(--muted); line-height: 1.6; }
.empty-icon { width: 58px; height: 58px; display: grid; place-items: center; border-radius: 16px; color: var(--blue-600); background: #edf2ff; font-size: 25px; }
.filter-chips { display: flex; gap: 8px; padding: 15px 22px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.chip { padding: 7px 12px; border: 1px solid var(--line); border-radius: 99px; color: var(--muted); background: #fff; font-size: 12px; font-weight: 750; white-space: nowrap; }
.chip.is-active { color: #fff; border-color: var(--navy-800); background: var(--navy-800); }
.info-banner { margin: 22px; padding: 16px 18px; display: flex; align-items: center; gap: 12px; border: 1px solid #d8e2ff; border-radius: 13px; color: var(--navy-800); background: #f1f5ff; }
.info-banner span { font-size: 24px; color: var(--blue-600); }
.info-banner p { margin: 0; }

.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.settings-card { min-height: 115px; padding: 22px; display: grid; grid-template-columns: 48px 1fr auto; align-items: center; gap: 16px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; box-shadow: 0 10px 32px rgba(20,38,78,.05); transition: .2s ease; }
.settings-card:hover { transform: translateY(-2px); border-color: #cbd6ef; }
.settings-card > span { width: 46px; height: 46px; display: grid; place-items: center; border-radius: 13px; color: var(--blue-600); background: #edf2ff; font-size: 20px; }
.settings-card h3 { margin: 0 0 5px; }
.settings-card p { margin: 0; color: var(--muted); }
.settings-card b { color: var(--blue-600); }
.settings-card em { padding: 5px 8px; border-radius: 99px; color: var(--muted); background: #eef1f6; font-size: 11px; font-style: normal; font-weight: 800; }
.settings-card.is-future { opacity: .75; }

.guest-body { background: #fff; }
.login-shell { min-height: 100vh; display: grid; grid-template-columns: minmax(420px, .9fr) minmax(500px, 1.1fr); }
.login-brand-panel { position: relative; overflow: hidden; display: flex; align-items: center; padding: 70px clamp(40px, 7vw, 110px); color: #fff; background: linear-gradient(145deg, var(--navy-950), #0e2b68); }
.login-brand-panel::before { content: ""; position: absolute; width: 420px; height: 420px; right: -170px; top: -160px; border: 1px solid rgba(255,255,255,.1); border-radius: 50%; box-shadow: 0 0 0 70px rgba(255,255,255,.025), 0 0 0 140px rgba(255,255,255,.018); }
.login-brand-inner { position: relative; z-index: 2; max-width: 520px; }
.login-brand-inner img { width: 210px; padding: 13px 17px; border-radius: 15px; background: #fff; box-shadow: 0 20px 50px rgba(0,0,0,.18); }
.login-kicker { margin: 55px 0 14px; color: #88a8ff; text-transform: uppercase; letter-spacing: .14em; font-size: 12px; font-weight: 800; }
.login-brand-inner h1 { margin: 0; font-size: clamp(42px, 5vw, 68px); line-height: .98; letter-spacing: -.055em; }
.login-brand-inner > p:last-child { max-width: 430px; margin-top: 25px; color: #b9c8e5; font-size: 17px; line-height: 1.65; }
.login-accent { position: absolute; width: 8px; height: 160px; left: 0; top: 50%; transform: translateY(-50%); border-radius: 0 8px 8px 0; background: linear-gradient(var(--blue-500), var(--teal-500)); }
.login-form-panel { display: grid; place-items: center; padding: 45px; background: #f8f9fc; }
.login-card { width: min(100%, 430px); padding: 42px; border: 1px solid var(--line); border-radius: 22px; background: #fff; box-shadow: 0 28px 70px rgba(20,38,78,.1); }
.login-card h2 { margin: 7px 0 8px; font-size: 32px; letter-spacing: -.035em; }
.muted { margin: 0 0 27px; color: var(--muted); line-height: 1.55; }
.field { display: grid; gap: 8px; margin-bottom: 18px; }
.field span { font-size: 12px; font-weight: 800; }
.field input { width: 100%; height: 49px; padding: 0 14px; border: 1px solid #d9deea; border-radius: 11px; color: var(--ink); outline: 0; background: #fbfcfe; transition: .2s ease; }
.field select { width: 100%; height: 49px; padding: 0 38px 0 14px; border: 1px solid #d9deea; border-radius: 11px; color: var(--ink); outline: 0; background: #fbfcfe; }
.field input:focus, .field select:focus { border-color: var(--blue-500); box-shadow: 0 0 0 4px rgba(53,108,232,.1); background: #fff; }
.field small { color: var(--muted); line-height: 1.4; }
.alert { margin-bottom: 20px; padding: 12px 14px; border-radius: 10px; font-size: 13px; line-height: 1.45; }
.alert-error { color: #9d2f3e; background: #fff0f2; border: 1px solid #ffd6dc; }
.alert-success { color: #17665f; background: #eaf8f5; border: 1px solid #c6eee8; }
.login-note { display: block; margin-top: 20px; text-align: center; color: #9ba3b5; }

.content-narrow { max-width: 720px; }
.back-link { display: inline-flex; margin-bottom: 18px; color: var(--blue-600); font-size: 13px; font-weight: 800; }
.form-panel { max-width: 760px; }
.settings-form { padding: 25px; }
.form-actions { display: flex; justify-content: flex-end; align-items: center; gap: 10px; margin-top: 24px; }
.import-alert { margin-bottom: 18px; }
.import-alert a { margin-left: 7px; }
.import-upload-panel { max-width: 900px; }
.upload-box { min-height: 160px; padding: 28px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; border: 2px dashed #cbd6ef; border-radius: 15px; color: var(--navy-800); background: #f8faff; text-align: center; cursor: pointer; }
.upload-box:hover { border-color: var(--blue-500); background: #f2f6ff; }
.upload-box input { width: min(100%, 360px); height: auto; margin-top: 12px; }
.upload-box small { color: var(--muted); line-height: 1.5; }
.upload-icon { width: 44px; height: 44px; display: grid; place-items: center; margin-bottom: 4px; border-radius: 13px; color: var(--blue-600); background: #e9efff; font-size: 23px; font-weight: 900; }
.step-badge { padding: 7px 10px; border-radius: 99px; color: var(--blue-600); background: #edf2ff; font-size: 11px; font-weight: 850; white-space: nowrap; }
.import-section { margin-top: 18px; }
.mapping-grid { padding: 24px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 16px; }
.form-hint { margin: -4px 24px 24px; padding: 13px 15px; border-radius: 11px; color: var(--muted); background: #f4f6fa; font-size: 12px; line-height: 1.5; }
.import-preview { max-height: 430px; }
.import-preview td { max-width: 270px; overflow: hidden; text-overflow: ellipsis; }
.import-confirm { padding: 20px 24px; display: flex; align-items: center; justify-content: space-between; gap: 20px; border-top: 1px solid var(--line); }
.check-field { display: inline-flex; align-items: center; gap: 9px; font-size: 13px; font-weight: 700; }
.check-field input { width: 18px; height: 18px; accent-color: var(--blue-600); }
.result-panel { margin-bottom: 18px; }
.error-list { max-height: 260px; margin: 0; padding: 20px 44px; overflow-y: auto; color: #7c3540; font-size: 13px; line-height: 1.65; }

@media (max-width: 1100px) {
    .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .dashboard-grid { grid-template-columns: 1fr; }
    .quick-panel { align-self: stretch; }
    .login-shell { grid-template-columns: 1fr 1fr; }
    .mapping-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 820px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar { position: fixed; left: -280px; transition: left .25s ease; }
    .sidebar.is-open { left: 0; }
    .mobile-menu { display: inline-grid; place-items: center; }
    .topbar { padding: 18px 20px; }
    .topbar-actions .button-secondary { display: none; }
    .page-content { padding: 23px 20px 40px; }
    .settings-grid { grid-template-columns: 1fr; }
    .mapping-grid { grid-template-columns: 1fr; }
    .login-shell { grid-template-columns: 1fr; }
    .login-brand-panel { display: none; }
    .login-form-panel { min-height: 100vh; padding: 22px; }
}

@media (max-width: 560px) {
    .metric-grid { grid-template-columns: 1fr; }
    .metric-card { min-height: 150px; }
    .topbar-actions .button { padding-inline: 12px; font-size: 12px; }
    .welcome-row { align-items: flex-start; gap: 14px; }
    .login-card { padding: 30px 24px; }
    .import-confirm { align-items: stretch; flex-direction: column; }
    .import-confirm .button { width: 100%; }
}
