/* ==========================================================================
   Matthew — design tokens & component system
   Loaded after the Tailwind CDN; Tailwind supplies utilities, this file
   supplies the persistent visual identity (fintech violet theme).
   ========================================================================== */

:root {
    --color-primary: #4935f5;
    --color-primary-dark: #3220d8;
    --color-primary-light: #7668ff;
    --color-primary-soft: #eeebff;

    --color-black: #080808;
    --color-ink: #171717;
    --color-text: #262626;
    --color-muted: #777777;
    --color-subtle: #a3a3a3;

    --color-background: #f3f3f5;
    --color-surface: #ffffff;
    --color-surface-soft: #f6f6f7;
    --color-surface-strong: #ececee;

    --color-border: #e4e4e7;

    --color-success: #18a957;
    --color-warning: #e99518;
    --color-danger: #dc3545;
    --color-info: #4935f5;

    --sidebar-width: 232px;
    --sidebar-collapsed-width: 84px;

    --radius-sm: 12px;
    --radius-md: 18px;
    --radius-lg: 24px;
    --radius-xl: 32px;
    --radius-pill: 999px;

    --shadow-soft: 0 8px 30px rgba(0, 0, 0, 0.05);
    --shadow-card: 0 14px 40px rgba(18, 18, 18, 0.07);
    --shadow-floating: 0 18px 50px rgba(30, 20, 120, 0.14);

    --violet-gradient: linear-gradient(145deg, #3825e7 0%, #5138f5 50%, #6049ff 100%);
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: Inter, "Plus Jakarta Sans", "Helvetica Neue", Arial, sans-serif;
    background: #ecebff;
    color: var(--color-text);
    -webkit-font-smoothing: antialiased;
}

/* ==========================================================================
   Application shell — rounded floating frame on a pale violet canvas
   ========================================================================== */

.app-shell {
    max-width: 1600px;
    min-height: calc(100vh - 40px);
    margin: 20px auto;
    border-radius: var(--radius-xl);
    overflow: hidden;
    background: var(--color-surface);
    box-shadow: var(--shadow-floating);
    display: flex;
}

.app-canvas {
    background: var(--color-background);
}

@media (max-width: 1439px) {
    .app-shell { margin: 12px; max-width: none; }
}
@media (max-width: 1023px) {
    .app-shell {
        margin: 0;
        border-radius: 0;
        min-height: 100vh;
        box-shadow: none;
    }
}

/* ==========================================================================
   Sidebar — electric violet with black pill selection
   ========================================================================== */

.side-nav {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: var(--violet-gradient);
    color: #fff;
    display: flex;
    flex-direction: column;
}

.side-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 26px 22px 18px;
}
.side-brand-mark {
    width: 40px;
    height: 40px;
    border-radius: 14px;
    background: var(--color-black);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 18px;
    flex-shrink: 0;
}
.side-brand-name { font-weight: 700; font-size: 17px; letter-spacing: -0.01em; }
.side-brand-sub { font-size: 11px; color: rgba(255, 255, 255, 0.65); }

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 18px;
    margin: 2px 14px;
    border-radius: var(--radius-pill);
    color: rgba(255, 255, 255, 0.82);
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    white-space: nowrap;
    transition: background-color 160ms ease, color 160ms ease, transform 160ms ease;
}
.nav-item:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    transform: translateX(1px);
}
.nav-item.active {
    background: #050505;
    color: #ffffff;
    font-weight: 600;
}
.nav-item svg { width: 20px; height: 20px; flex-shrink: 0; }

.side-footer {
    margin-top: auto;
    padding: 16px 20px 22px;
    border-top: 1px solid rgba(255, 255, 255, 0.14);
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
}
.side-footer .avatar-badge { background: rgba(255, 255, 255, 0.18); color: #fff; }

/* Collapse to icons on medium desktop widths */
@media (min-width: 1024px) and (max-width: 1279px) {
    .side-nav { width: var(--sidebar-collapsed-width); }
    .side-nav .nav-label,
    .side-nav .side-brand-text,
    .side-nav .side-footer-text { display: none; }
    .side-nav .nav-item { justify-content: center; padding: 12px; margin: 2px 12px; }
    .side-brand { justify-content: center; padding: 24px 0 14px; }
    .side-footer { justify-content: center; }
}

/* Mobile drawer keeps the identical violet identity */
.drawer-nav {
    background: var(--violet-gradient);
    color: #fff;
}
body.drawer-open { overflow: hidden; }

/* ==========================================================================
   Topbar
   ========================================================================== */

.topbar {
    height: 64px;
    background: var(--color-surface);
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 0 20px;
    position: sticky;
    top: 0;
    z-index: 30;
    border-bottom: 1px solid var(--color-border);
}
@media (min-width: 640px) { .topbar { padding: 0 28px; } }

.topbar-title {
    font-size: 19px;
    font-weight: 700;
    color: var(--color-ink);
    letter-spacing: -0.01em;
    line-height: 1.15;
}
.topbar-greeting {
    font-size: 11px;
    color: var(--color-muted);
    font-weight: 500;
}

.topbar-search {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--color-surface-soft);
    border-radius: var(--radius-pill);
    height: 42px;
    padding: 0 18px;
    min-width: 0;
    flex: 1;
    max-width: 380px;
    transition: box-shadow 160ms ease, background-color 160ms ease;
}
.topbar-search:focus-within {
    background: #fff;
    box-shadow: 0 0 0 4px rgba(73, 53, 245, 0.12), inset 0 0 0 1px var(--color-primary-light);
}
.topbar-search input {
    background: transparent;
    border: 0;
    outline: none;
    font-size: 14px;
    width: 100%;
    color: var(--color-ink);
}
.topbar-search svg { width: 17px; height: 17px; color: var(--color-subtle); flex-shrink: 0; }
@media (max-width: 767px) { .topbar-search { display: none; } }

.icon-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--color-surface-soft);
    color: var(--color-ink);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: relative;
    flex-shrink: 0;
    transition: background-color 160ms ease, transform 160ms ease;
}
.icon-btn:hover { background: var(--color-surface-strong); }
.icon-btn .dot {
    position: absolute;
    top: 9px;
    right: 10px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-danger);
    border: 2px solid #fff;
}

.avatar-badge {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--color-primary-soft);
    color: var(--color-primary-dark);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    flex-shrink: 0;
    overflow: hidden;
}

.menu-pop {
    position: absolute;
    right: 0;
    top: calc(100% + 10px);
    min-width: 200px;
    background: #fff;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-card);
    border: 1px solid var(--color-border);
    padding: 8px;
    z-index: 50;
}
.menu-pop a, .menu-pop button {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    text-align: left;
    padding: 10px 12px;
    border-radius: 12px;
    font-size: 14px;
    color: var(--color-text);
    transition: background-color 140ms ease;
}
.menu-pop a:hover, .menu-pop button:hover { background: var(--color-surface-soft); }

/* ==========================================================================
   Cards
   ========================================================================== */

.ui-card {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    padding: 24px;
}
.ui-card-soft {
    background: var(--color-surface-soft);
    border-radius: var(--radius-md);
    padding: 20px;
}
.ui-card-primary {
    background: var(--violet-gradient);
    color: #fff;
    border-radius: 28px;
    padding: 28px;
    box-shadow: var(--shadow-floating);
}
.ui-card-dark {
    background: var(--color-black);
    color: #fff;
    border-radius: var(--radius-lg);
    padding: 24px;
}
.ui-card-stat {
    background: var(--color-surface);
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    padding: 18px 20px;
}
.ui-card-hover { transition: transform 160ms ease, box-shadow 160ms ease; }
.ui-card-hover:hover { transform: translateY(-2px); box-shadow: var(--shadow-card); }

/* Hero quick actions — black circles with white icons */
.quick-action {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    color: rgba(255, 255, 255, 0.92);
    font-size: 12px;
    font-weight: 500;
    text-decoration: none;
}
.quick-action-circle {
    width: 54px;
    height: 54px;
    border-radius: 50%;
    background: var(--color-black);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 160ms ease, background-color 160ms ease;
}
.quick-action:hover .quick-action-circle { transform: translateY(-2px); background: #1d1d1f; }
.quick-action-circle svg { width: 22px; height: 22px; }

/* Horizontal scroll strips */
.scroll-strip {
    display: flex;
    gap: 16px;
    overflow-x: auto;
    padding-bottom: 6px;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
}
.scroll-strip::-webkit-scrollbar { height: 6px; }
.scroll-strip::-webkit-scrollbar-thumb { background: var(--color-surface-strong); border-radius: 999px; }
.scroll-strip > * { scroll-snap-align: start; flex-shrink: 0; }

/* Customer avatar strip */
.customer-chip {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    width: 72px;
    text-decoration: none;
    color: var(--color-text);
    font-size: 12px;
    font-weight: 500;
}
.customer-chip-avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 17px;
    transition: transform 160ms ease;
}
.customer-chip:hover .customer-chip-avatar { transform: translateY(-2px); }

/* Payment list rows */
.pay-row {
    display: flex;
    align-items: center;
    gap: 14px;
    background: var(--color-surface-soft);
    border-radius: 20px;
    padding: 14px 18px;
}

/* ==========================================================================
   Empty states
   ========================================================================== */

.empty-icon {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--color-primary-soft);
    margin: 0 auto 14px;
    position: relative;
}
.empty-icon::after {
    content: "";
    position: absolute;
    inset: 14px;
    background-color: var(--color-primary);
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='black' stroke-width='1.8'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='M20 13V6a2 2 0 00-2-2H6a2 2 0 00-2 2v7m16 0v5a2 2 0 01-2 2H6a2 2 0 01-2-2v-5m16 0h-5l-2 2h-2l-2-2H4'/%3E%3C/svg%3E") center / contain no-repeat;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='black' stroke-width='1.8'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='M20 13V6a2 2 0 00-2-2H6a2 2 0 00-2 2v7m16 0v5a2 2 0 01-2 2H6a2 2 0 01-2-2v-5m16 0h-5l-2 2h-2l-2-2H4'/%3E%3C/svg%3E") center / contain no-repeat;
}

/* ==========================================================================
   Status badges — soft pills
   ========================================================================== */

.st-badge {
    display: inline-flex;
    align-items: center;
    border-radius: var(--radius-pill);
    padding: 3px 10px;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
}
.st-neutral  { background: var(--color-surface-strong); color: #52525b; }
.st-violet   { background: var(--color-primary-soft); color: var(--color-primary-dark); }
.st-green    { background: #e2f6ea; color: #12723d; }
.st-amber    { background: #fdf0dd; color: #a05e08; }
.st-red      { background: #fde7e9; color: #b02a37; }
.st-black    { background: var(--color-black); color: #fff; }
.st-muted-red { background: #f6e8ea; color: #9a5560; }

/* ==========================================================================
   Toasts
   ========================================================================== */

.matthew-toast {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 13px 18px;
    border-radius: 18px;
    font-size: 13.5px;
    font-weight: 500;
    background: var(--color-surface);
    color: var(--color-ink);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-card);
    animation: toast-in 200ms ease-out;
}
.matthew-toast span:first-child {
    width: 22px; height: 22px; border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 12px; flex-shrink: 0; color: #fff;
}
.matthew-toast-success span:first-child { background: var(--color-success); }
.matthew-toast-error span:first-child { background: var(--color-danger); }
.matthew-toast-info span:first-child { background: var(--color-primary); }
@keyframes toast-in {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: translateY(0); }
}
@media (max-width: 639px) {
    #toast-root {
        top: auto !important;
        bottom: 18px;
        right: 50% !important;
        transform: translateX(50%);
    }
    @keyframes toast-in {
        from { opacity: 0; transform: translateY(8px); }
        to   { opacity: 1; transform: translateY(0); }
    }
}

/* ==========================================================================
   Progress bars
   ========================================================================== */

.progress-track {
    background: var(--color-surface-strong);
    border-radius: var(--radius-pill);
    height: 9px;
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    border-radius: var(--radius-pill);
    transition: width 220ms ease, background-color 220ms ease;
}

/* ==========================================================================
   Loading spinner
   ========================================================================== */

.matthew-spinner {
    width: 1.1rem; height: 1.1rem; border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-top-color: #fff;
    animation: spin 0.7s linear infinite;
    display: inline-block;
    vertical-align: -3px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ==========================================================================
   Auth pages
   ========================================================================== */

.auth-bg {
    min-height: 100vh;
    background: var(--violet-gradient);
    font-family: Inter, "Plus Jakarta Sans", "Helvetica Neue", Arial, sans-serif;
}

/* ==========================================================================
   Reskin of Tailwind utility patterns used across existing pages
   (buttons → pills, indigo → electric violet, black secondaries)
   ========================================================================== */

button.rounded-lg, a.rounded-lg, label.rounded-lg { border-radius: var(--radius-pill) !important; }

.bg-indigo-600 { background: var(--color-primary) !important; }
.hover\:bg-indigo-700:hover { background: var(--color-primary-dark) !important; }
.text-indigo-600, .text-indigo-700 { color: var(--color-primary) !important; }
.bg-indigo-50 { background: var(--color-primary-soft) !important; }
.border-indigo-200 { border-color: #d5cdff !important; }
.hover\:bg-indigo-50:hover { background: var(--color-primary-soft) !important; }
.bg-indigo-100 { background: var(--color-primary-soft) !important; }

a.bg-slate-800, button.bg-slate-800 { background: var(--color-black) !important; }
a.hover\:bg-slate-700:hover, button.hover\:bg-slate-700:hover { background: #1f1f22 !important; }

.bg-slate-100 { background: var(--color-background) !important; }
.text-slate-800 { color: var(--color-ink) !important; }

/* Cards drawn with utilities pick up the softer border + radius */
div.rounded-2xl { border-radius: var(--radius-lg); }
.border-slate-200 { border-color: var(--color-border) !important; }
.shadow-sm { box-shadow: none !important; }

/* ==========================================================================
   Forms — filled, rounded, violet focus ring
   ========================================================================== */

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], input[type="search"], input[type="tel"], input[type="url"],
select, textarea, .form-control {
    background: #f4f4f5 !important;
    border: 1px solid transparent !important;
    border-radius: 16px !important;
    min-height: 46px;
    color: var(--color-ink);
    font-size: 14px;
    padding-left: 14px;
    padding-right: 14px;
    transition: background-color 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}
textarea { min-height: 0; padding-top: 12px; padding-bottom: 12px; }
input:focus, select:focus, textarea:focus, .form-control:focus {
    background: #fff !important;
    border-color: #6a58ff !important;
    box-shadow: 0 0 0 4px rgba(73, 53, 245, 0.12) !important;
    outline: none;
}
input[readonly] { background: var(--color-surface-strong) !important; color: var(--color-muted); }
input[type="checkbox"], input[type="radio"] {
    background: #fff !important;
    border: 1.5px solid #c9c9cf !important;
    min-height: 0;
    border-radius: 6px !important;
    padding: 0;
}
input[type="radio"] { border-radius: 50% !important; }
input[type="checkbox"]:checked, input[type="radio"]:checked {
    background-color: var(--color-primary) !important;
    border-color: var(--color-primary) !important;
}
input[type="color"] {
    padding: 4px !important;
    min-height: 42px;
    border-radius: 12px !important;
    background: #f4f4f5 !important;
}
input[type="file"] { background: transparent !important; border: 0 !important; min-height: 0; padding-left: 0; }

/* Compact controls inside invoice item rows */
.item-row input, .item-row select, .item-row textarea {
    min-height: 40px;
    border-radius: 12px !important;
    font-size: 13px;
}

/* Hide number-input spinners in item tables */
.item-row input[type="number"]::-webkit-outer-spin-button,
.item-row input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.item-row input[type="number"] { -moz-appearance: textfield; appearance: textfield; }

/* ==========================================================================
   Invoice builder preview panel
   ========================================================================== */

.preview-panel-bg {
    background: #ecebf3;
    background-image: radial-gradient(#dcd9ea 1px, transparent 1px);
    background-size: 18px 18px;
    border-radius: var(--radius-lg);
}
#invoice-preview-scale { transform-origin: top center; transition: transform 150ms ease; }

/* ==========================================================================
   Accessibility
   ========================================================================== */

:focus-visible {
    outline: 3px solid rgba(73, 53, 245, 0.45);
    outline-offset: 2px;
}

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