:root {
    --brand-900: #3b2e7e;
    --brand-700: #5b45c4;
    --brand-600: #6c5ce7;
    --brand-500: #7d6df0;
    --brand-100: #ece9fb;
    --ink-900: #1f2233;
    --ink-700: #3d4257;
    --ink-500: #6b7085;
    --ink-300: #9aa0b4;
    --line: #e6e8f0;
    --bg: #f5f6fa;
    --card: #ffffff;
    --green: #2fa76a;
    --green-bg: #e6f6ee;
    --red: #d9435e;
    --red-bg: #fce8ec;
    --amber: #d98a1f;
    --blue: #3576d9;
    --blue-bg: #e7f0fc;
    --radius: 12px;
    --shadow: 0 1px 2px rgba(31, 34, 51, 0.06), 0 8px 24px rgba(31, 34, 51, 0.06);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--ink-900);
    font-size: 14px;
    line-height: 1.5;
}

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

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

.sidebar {
    width: 240px;
    background: linear-gradient(180deg, var(--brand-700) 0%, var(--brand-900) 100%);
    color: #fff;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    flex-shrink: 0;
}

.sidebar-brand {
    padding: 22px 22px 18px;
    font-size: 17px;
    font-weight: 700;
    letter-spacing: 0.2px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}
.sidebar-brand span { opacity: 0.7; font-weight: 400; display: block; font-size: 12px; margin-top: 2px; }

.nav { padding: 12px 10px; overflow-y: auto; flex: 1; }
.nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 14px;
    color: rgba(255, 255, 255, 0.82);
    border-radius: 8px;
    margin-bottom: 2px;
    font-weight: 500;
    text-decoration: none;
    transition: background 0.15s, color 0.15s;
}
.nav a:hover { background: rgba(255, 255, 255, 0.1); color: #fff; text-decoration: none; }
.nav a.active { background: rgba(255, 255, 255, 0.16); color: #fff; }
.nav .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: 0.6; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
    height: 62px;
    background: var(--card);
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 10;
}
.topbar .page-title { font-size: 16px; font-weight: 600; }
.topbar .right { display: flex; align-items: center; gap: 14px; }

.company-switch select {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 7px 12px;
    background: #fff;
    font-size: 13px;
    color: var(--ink-700);
}
.env-pill {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    padding: 4px 9px;
    border-radius: 999px;
    letter-spacing: 0.4px;
}
.env-sandbox { background: var(--amber); color: #fff; }
.env-production { background: var(--green); color: #fff; }

.user-chip {
    display: flex; align-items: center; gap: 8px;
    font-weight: 600; color: var(--ink-700);
}
.avatar {
    width: 32px; height: 32px; border-radius: 50%;
    background: var(--brand-100); color: var(--brand-700);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 13px;
}

.content { padding: 26px 24px; flex: 1; }

.page-head {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 20px; flex-wrap: wrap; gap: 12px;
}
.page-head h1 { font-size: 22px; margin: 0; font-weight: 700; }
.page-head p { margin: 4px 0 0; color: var(--ink-500); }

.btn {
    display: inline-flex; align-items: center; gap: 7px;
    border: none; border-radius: 9px; padding: 10px 16px;
    font-size: 14px; font-weight: 600; cursor: pointer;
    text-decoration: none; transition: filter 0.15s, background 0.15s;
}
.btn:hover { text-decoration: none; filter: brightness(0.96); }
.btn-primary { background: var(--brand-600); color: #fff; }
.btn-success { background: var(--green); color: #fff; }
.btn-danger { background: var(--red); color: #fff; }
.btn-light { background: #fff; color: var(--ink-700); border: 1px solid var(--line); }
.btn-ghost { background: var(--brand-100); color: var(--brand-700); }
.btn-sm { padding: 6px 11px; font-size: 12.5px; border-radius: 7px; }

.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; margin-bottom: 24px; }
.stat {
    background: var(--card); border: 1px solid var(--line);
    border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow);
}
.stat .label { color: var(--ink-500); font-size: 13px; font-weight: 500; }
.stat .value { font-size: 26px; font-weight: 800; margin-top: 6px; }
.stat .sub { color: var(--ink-300); font-size: 12px; margin-top: 4px; }
.stat.accent { background: linear-gradient(135deg, var(--brand-600), var(--brand-700)); border: none; color: #fff; }
.stat.accent .label, .stat.accent .sub { color: rgba(255,255,255,0.8); }

.card {
    background: var(--card); border: 1px solid var(--line);
    border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 22px;
}
.card-head {
    padding: 16px 20px; border-bottom: 1px solid var(--line);
    display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.card-head h2 { font-size: 15px; margin: 0; font-weight: 700; }
.card-body { padding: 20px; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.search-box { display: flex; gap: 8px; align-items: center; }
.search-box input {
    border: 1px solid var(--line); border-radius: 9px; padding: 9px 13px;
    min-width: 240px; font-size: 14px;
}

table.data { width: 100%; border-collapse: collapse; }
table.data th {
    text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px;
    color: var(--ink-500); padding: 12px 16px; border-bottom: 1px solid var(--line); background: #fafbff;
}
table.data td { padding: 13px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data tbody tr:hover, table.data tr:hover td { background: #fbfbfe; }
table.data td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data th.num { text-align: right; }
.empty { text-align: center; color: var(--ink-300); padding: 40px 0; }

.badge { display: inline-block; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.badge-green { background: var(--green-bg); color: var(--green); }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-blue { background: var(--blue-bg); color: var(--blue); }
.badge-grey { background: #eef0f5; color: var(--ink-500); }

.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px 22px; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid .col-2 { grid-column: span 2; }
.field { display: flex; flex-direction: column; }
.field label { font-size: 13px; font-weight: 600; color: var(--ink-700); margin-bottom: 6px; }
.field .hint { font-size: 12px; color: var(--ink-300); margin-top: 4px; }
.field input, .field select, .field textarea {
    border: 1px solid var(--line); border-radius: 9px; padding: 10px 13px;
    font-size: 14px; background: #fff; width: 100%; font-family: inherit;
}
.field input:focus, .field select:focus, .field textarea:focus {
    outline: none; border-color: var(--brand-500); box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.14);
}
.field textarea { min-height: 70px; resize: vertical; }
.checkline { display: flex; align-items: center; gap: 8px; }
.checkline input { width: auto; }

.form-actions { display: flex; gap: 12px; margin-top: 22px; }

.flash { padding: 13px 18px; border-radius: 10px; margin-bottom: 20px; font-weight: 500; }
.flash-success { background: var(--green-bg); color: #1c6b45; }
.flash-error { background: var(--red-bg); color: #a32338; }
.flash-info { background: var(--blue-bg); color: #2456a3; }

.pagination { display: flex; gap: 6px; padding: 16px 20px; justify-content: flex-end; }
.page-link {
    padding: 7px 12px; border: 1px solid var(--line); border-radius: 8px;
    color: var(--ink-700); font-weight: 600; font-size: 13px;
}
.page-link:hover { background: #f4f4fb; text-decoration: none; }
.page-link.active { background: var(--brand-600); color: #fff; border-color: var(--brand-600); }
.page-link.disabled { opacity: 0.45; pointer-events: none; }

.login-wrap { display: flex; min-height: 100vh; align-items: center; justify-content: center; background: linear-gradient(135deg, var(--brand-700), var(--brand-900)); padding: 20px; }
.login-card { background: #fff; border-radius: 16px; padding: 34px; width: 100%; max-width: 380px; box-shadow: 0 20px 50px rgba(0,0,0,0.25); }
.login-card h1 { font-size: 22px; margin: 0 0 4px; }
.login-card p { color: var(--ink-500); margin: 0 0 22px; }
.login-card .field { margin-bottom: 16px; }
.login-card .btn { width: 100%; justify-content: center; }

.items-table { width: 100%; border-collapse: collapse; margin-top: 8px; }
.items-table th { font-size: 12px; text-transform: uppercase; color: var(--ink-500); padding: 8px; text-align: left; border-bottom: 1px solid var(--line); }
.items-table td { padding: 6px; border-bottom: 1px solid var(--line); }
.items-table input, .items-table select { border: 1px solid var(--line); border-radius: 7px; padding: 7px 8px; width: 100%; font-size: 13px; }
.items-table .num { text-align: right; }

.totals { margin-top: 18px; width: 320px; margin-left: auto; }
.totals .row { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px dashed var(--line); }
.totals .row.grand { font-weight: 800; font-size: 16px; border-bottom: none; border-top: 2px solid var(--ink-900); margin-top: 6px; padding-top: 12px; }

.invoice-doc { background: #fff; max-width: 820px; margin: 0 auto; padding: 40px; border-radius: 12px; box-shadow: var(--shadow); }
.invoice-doc .head { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 3px solid var(--brand-600); padding-bottom: 18px; }
.invoice-doc .fbr-box { text-align: center; }
.invoice-doc .fbr-box .irn { font-size: 12px; color: var(--ink-500); margin-top: 6px; word-break: break-all; }
.invoice-doc .parties { display: flex; justify-content: space-between; margin: 24px 0; gap: 24px; }
.invoice-doc .parties .box { flex: 1; }
.invoice-doc .parties h4 { margin: 0 0 6px; font-size: 12px; text-transform: uppercase; color: var(--ink-500); }

@media (max-width: 1024px) {
    .cards { grid-template-columns: repeat(2, 1fr); }
    .form-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 720px) {
    .sidebar { position: fixed; left: -240px; z-index: 40; transition: left 0.2s; }
    .sidebar.open { left: 0; }
    .cards, .form-grid { grid-template-columns: 1fr; }
    .content { padding: 18px 14px; }
}
.menu-toggle { display: none; background: none; border: none; font-size: 22px; cursor: pointer; color: var(--brand-700); }
@media (max-width: 720px) { .menu-toggle { display: inline-block; } }

.sidebar-brand { display: flex; align-items: center; gap: 12px; }
.sidebar-brand .brand-logo { flex-shrink: 0; }
.sidebar-brand .brand-logo img {
    max-height: 40px; max-width: 90px; border-radius: 8px;
    background: #fff; padding: 4px; display: block;
}
.sidebar-brand .brand-text { line-height: 1.2; }

.nav { scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.28) transparent; }
.nav::-webkit-scrollbar { width: 7px; }
.nav::-webkit-scrollbar-track { background: transparent; }
.nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.22); border-radius: 999px; }
.nav::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.38); }

.sidebar-foot {
    padding: 10px; border-top: 1px solid rgba(255,255,255,0.12);
    flex-shrink: 0; background: rgba(0,0,0,0.08);
}
.logout-btn {
    all: unset; box-sizing: border-box; display: flex; align-items: center; gap: 10px;
    padding: 11px 14px; color: rgba(255,255,255,0.82); border-radius: 8px;
    font-weight: 500; cursor: pointer; width: 100%; transition: background 0.15s, color 0.15s;
}
.logout-btn:hover { background: rgba(255,255,255,0.12); color: #fff; }

.switch { position: relative; display: inline-block; width: 46px; height: 26px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
    position: absolute; cursor: pointer; inset: 0;
    background: #cdd2e0; border-radius: 999px; transition: background 0.2s;
}
.switch .slider::before {
    content: ""; position: absolute; height: 20px; width: 20px; left: 3px; top: 3px;
    background: #fff; border-radius: 50%; transition: transform 0.2s; box-shadow: 0 1px 3px rgba(0,0,0,0.25);
}
.switch input:checked + .slider { background: var(--green); }
.switch input:checked + .slider::before { transform: translateX(20px); }

.theme-presets { display: flex; flex-wrap: wrap; gap: 10px; }
.theme-swatch {
    width: 34px; height: 34px; border-radius: 9px; border: 2px solid #fff;
    box-shadow: 0 0 0 1px var(--line); cursor: pointer; padding: 0;
}
.theme-swatch:hover { box-shadow: 0 0 0 2px var(--brand-500); }
.field input[type="color"] {
    padding: 4px; height: 42px; cursor: pointer;
}
.field input[type="file"] { padding: 8px; background: #fbfbfe; }
