: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; }

@keyframes fadeSlideUp {
    from { opacity: 0; transform: translateY(14px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes flashIn {
    from { opacity: 0; transform: translateY(-10px) scale(0.99); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes navPop {
    from { opacity: 0; transform: translateX(-8px); }
    to { opacity: 1; transform: translateX(0); }
}
@keyframes spin {
    to { transform: rotate(360deg); }
}
@keyframes shimmer {
    0% { background-position: -400px 0; }
    100% { background-position: 400px 0; }
}
@keyframes pulseGlow {
    0%, 100% { box-shadow: 0 0 0 0 rgba(108, 92, 231, 0.35); }
    50% { box-shadow: 0 0 0 6px rgba(108, 92, 231, 0); }
}

.content { animation: fadeIn 0.35s ease both; }
.page-head { animation: fadeSlideUp 0.4s ease both; }

.content .card {
    animation: fadeSlideUp 0.45s cubic-bezier(0.22, 1, 0.36, 1) both;
    transition: box-shadow 0.25s ease, transform 0.25s ease;
}
.content .card:nth-child(1) { animation-delay: 0.02s; }
.content .card:nth-child(2) { animation-delay: 0.08s; }
.content .card:nth-child(3) { animation-delay: 0.14s; }
.content .card:nth-child(4) { animation-delay: 0.20s; }
.content .card:nth-child(5) { animation-delay: 0.26s; }
.content .card:nth-child(6) { animation-delay: 0.32s; }
.content .card:nth-child(n+7) { animation-delay: 0.36s; }
.content .card:hover {
    box-shadow: 0 10px 30px -12px rgba(20, 20, 60, 0.22);
    transform: translateY(-2px);
}
.content .card:focus-within {
    position: relative;
    z-index: 30;
}

.btn {
    transition: transform 0.12s ease, box-shadow 0.2s ease, background 0.2s ease, filter 0.2s ease;
    will-change: transform;
}
.btn:hover { transform: translateY(-1px); filter: brightness(1.03); }
.btn:active { transform: translateY(1px) scale(0.99); }
.btn-primary:hover, .btn-success:hover, .btn-danger:hover {
    box-shadow: 0 8px 18px -8px rgba(20, 20, 60, 0.5);
}

.nav a {
    transition: background 0.18s ease, color 0.18s ease, padding-left 0.18s ease;
    animation: navPop 0.35s ease both;
}
.nav a:hover { padding-left: 20px; }
.nav a .dot { transition: transform 0.18s ease, background 0.18s ease; }
.nav a:hover .dot { transform: scale(1.5); }
.nav a.active .dot { transform: scale(1.6); animation: pulseGlow 2.4s ease-in-out infinite; }

.data tbody tr { transition: background 0.15s ease, transform 0.15s ease; }
.data tbody tr:hover { background: rgba(108, 92, 231, 0.06); }

.field input, .field select, .field textarea {
    transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}
.field input:focus, .field select:focus, .field textarea:focus {
    box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.16);
}

.flash { animation: flashIn 0.4s cubic-bezier(0.22, 1, 0.36, 1) both; }

.badge, .env-pill { transition: transform 0.15s ease, box-shadow 0.15s ease; }
.badge:hover, .env-pill:hover { transform: translateY(-1px); }

.topbar { transition: box-shadow 0.25s ease; }

.user-chip .avatar { transition: transform 0.2s ease; }
.user-chip:hover .avatar { transform: scale(1.08) rotate(-3deg); }

.theme-swatch { transition: transform 0.15s ease, box-shadow 0.15s ease; }
.theme-swatch:hover { transform: translateY(-2px) scale(1.06); }

.brand-logo img, .sidebar-brand { transition: transform 0.25s ease; }
.sidebar-brand:hover .brand-logo img { transform: scale(1.05); }

.spinner {
    display: inline-block; width: 18px; height: 18px;
    border: 2px solid rgba(108, 92, 231, 0.25); border-top-color: var(--brand-600);
    border-radius: 50%; animation: spin 0.7s linear infinite; vertical-align: middle;
}
.skeleton {
    background: linear-gradient(90deg, #eef0f6 25%, #f6f7fb 37%, #eef0f6 63%);
    background-size: 800px 100%; animation: shimmer 1.4s infinite linear; border-radius: 8px;
}

.login-card { animation: fadeSlideUp 0.5s cubic-bezier(0.22, 1, 0.36, 1) both; }
.login-card h1 { animation: fadeSlideUp 0.6s ease both; }

.switch .slider, .switch .slider::before { transition: background 0.25s ease, transform 0.25s ease; }

a, .btn, button { -webkit-tap-highlight-color: transparent; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
}

@keyframes rippleFx {
    to { transform: scale(2.4); opacity: 0; }
}

.bell { position: relative; text-decoration: none; font-size: 20px; line-height: 1; padding: 6px; border-radius: 10px; transition: background 0.15s ease, transform 0.15s ease; }
.bell:hover { background: rgba(108,92,231,0.10); transform: translateY(-1px); }
.bell-badge { position: absolute; top: -2px; right: -3px; background: var(--red); color: #fff; font-size: 10px; font-weight: 700; min-width: 17px; height: 17px; line-height: 17px; text-align: center; border-radius: 999px; padding: 0 4px; box-shadow: 0 0 0 2px #fff; }
.alert-row { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); transition: background 0.15s ease; }
.alert-row:hover { background: rgba(108,92,231,0.05); }
.alert-row:last-child { border-bottom: none; }
.alert-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.alert-danger .alert-dot { background: var(--red); }
.alert-warning .alert-dot { background: #f59e0b; }
.alert-info .alert-dot { background: var(--brand-600); }

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(24, 26, 45, 0.5);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.16s ease;
}
.modal-backdrop.open { opacity: 1; }
.modal-box {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: 0 24px 60px -20px rgba(20, 20, 60, 0.45);
    width: 100%;
    max-width: 440px;
    overflow: hidden;
    transform: translateY(10px) scale(0.98);
    transition: transform 0.16s ease;
}
.modal-backdrop.open .modal-box { transform: translateY(0) scale(1); }
.modal-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 18px 20px 0;
}
.modal-icon {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 19px;
    font-weight: 800;
    background: var(--blue-bg);
    color: var(--blue);
    flex: 0 0 auto;
}
.modal-box.danger .modal-icon { background: var(--red-bg); color: var(--red); }
.modal-title { font-size: 16px; font-weight: 700; color: var(--ink-900); }
.modal-body {
    padding: 10px 20px 4px 70px;
    color: var(--ink-500);
    font-size: 14px;
    line-height: 1.55;
    word-break: break-word;
}
.modal-foot {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px 20px 20px;
}
@media (max-width: 520px) {
    .modal-body { padding-left: 20px; }
    .modal-foot { flex-direction: column-reverse; }
    .modal-foot .btn { width: 100%; text-align: center; }
}
@media (prefers-reduced-motion: reduce) {
    .modal-backdrop, .modal-box { transition: none; }
}
@media print {
    .modal-backdrop { display: none !important; }
}
