/**
 * WSC Suite — standalone app design system.
 *
 * Same visual language as the WordPress plugin but zero dependencies.
 * Variables at the top; layout, components, then utilities below.
 *
 * @file    assets/css/app.css
 * @package WSC_App
 * @version 1.0.0
 */

/* ----------------------------------------------------------------
   Variables
---------------------------------------------------------------- */
:root {
    --color-brand:        #2271b1;
    --color-brand-dark:   #135e96;
    --color-brand-light:  #e8f1f8;
    --color-success:      #00a32a;
    --color-success-bg:   #edfaef;
    --color-danger:       #d63638;
    --color-danger-bg:    #fef0f0;
    --color-warning:      #996800;
    --color-warning-bg:   #fcf9e8;
    --color-text:         #1d2327;
    --color-text-muted:   #646970;
    --color-border:       #dcdcde;
    --color-bg:           #f0f0f1;
    --color-bg-card:      #ffffff;
    --color-sidebar-bg:   #1d2327;
    --color-sidebar-text: #c3c4c7;
    --color-sidebar-hover:#2c3338;
    --color-sidebar-active: #2271b1;
    --color-header-bg:    #0f172a;

    --sidebar-width:   220px;
    --header-height:    54px;
    --sync-height:      26px;
    /* Sticky chrome = header + sync strip (inventory: header full width, body below) */
    --chrome-height:    calc(var(--header-height) + var(--sync-height));
    --font-sans:        -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono:        'SFMono-Regular', Consolas, monospace;
    --radius:           4px;
    --radius-lg:        8px;
    --shadow-sm:        0 1px 2px rgba(0,0,0,.05);
    --shadow:           0 1px 4px rgba(0,0,0,.08);
}

/* ----------------------------------------------------------------
   Reset
---------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
body, h1, h2, h3, h4, p, ul, ol, figure, blockquote { margin: 0; padding: 0; }
ul, ol { list-style: none; }
img { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; }
a { color: var(--color-brand); text-decoration: none; }
a:hover { text-decoration: underline; }

body {
    font-family: var(--font-sans);
    font-size: 14px;
    color: var(--color-text);
    background: var(--color-bg);
    line-height: 1.5;
}

/* ----------------------------------------------------------------
   Layout: auth page
---------------------------------------------------------------- */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--color-bg);
}

.auth-card {
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 40px 36px;
    width: 100%;
    max-width: 400px;
}

.auth-logo {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 28px;
}

.auth-logo-mark {
    background: var(--color-brand);
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 1px;
    padding: 3px 8px;
    border-radius: var(--radius);
}

.auth-logo-suite {
    font-size: 16px;
    font-weight: 600;
    color: var(--color-text);
}

.auth-title {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 24px;
}

.auth-form .field + .field { margin-top: 16px; }

/* ----------------------------------------------------------------
   Layout: SaaS shell (inventory-aligned)
   ┌─────────────────────────────────────────────┐
   │  app-header (full width, sticky)            │
   │  sync-status (full width)                   │
   ├──────────────┬──────────────────────────────┤
   │  sidebar     │  main-content                │
   │  (primary    │  page-title + body           │
   │   nav)       │                              │
   └──────────────┴──────────────────────────────┘
---------------------------------------------------------------- */
.app-layout,
.app-layout--saas {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    background: var(--color-bg);
}

/* Row under chrome: sidebar | main */
.app-shell {
    display: flex;
    flex: 1 1 auto;
    min-height: 0;
    align-items: stretch;
    width: 100%;
}

/* Sidebar — left column under chrome (not full-viewport left of header) */
.sidebar {
    width: var(--sidebar-width);
    background: var(--color-sidebar-bg);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: sticky;
    top: var(--chrome-height);
    align-self: flex-start;
    height: calc(100vh - var(--chrome-height));
    max-height: calc(100vh - var(--chrome-height));
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 100;
    transition: width .2s ease;
    border-right: 1px solid rgba(255,255,255,.06);
}

.sidebar.is-collapsed {
    width: 56px;
    min-width: 56px;
    overflow-x: hidden;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255,255,255,.08);
    flex-shrink: 0;
    min-height: 52px;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 18px 16px 14px;
    flex: 1;
    min-width: 0;
}

.brand-mark {
    background: var(--color-brand);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1px;
    padding: 2px 6px;
    border-radius: 3px;
    flex-shrink: 0;
}

.brand-name {
    color: #fff;
    font-size: 15px;
    font-weight: 600;
}

.sidebar-toggle {
    background: none;
    border: none;
    color: var(--color-sidebar-text);
    padding: 8px 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color .1s, background .1s;
    border-radius: var(--radius);
    margin-right: 8px;
    flex-shrink: 0;
    z-index: 2;
    min-width: 40px;
    min-height: 40px;
}

.sidebar-toggle:hover {
    color: #fff;
    background: var(--color-sidebar-hover);
}

/* Collapsed rail: only hamburger + icons — never clip the toggle */
.sidebar.is-collapsed .sidebar-header {
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    padding: 8px 0;
}

.sidebar.is-collapsed .sidebar-brand {
    display: none;
}

.sidebar.is-collapsed .sidebar-toggle {
    margin: 0;
    width: 100%;
    border-radius: 0;
}

.sidebar.is-collapsed .sidebar-section-label {
    display: none;
}

.sidebar.is-collapsed .brand-name {
    display: none;
}

.sidebar-section {
    padding: 12px 0;
    border-bottom: 1px solid rgba(255,255,255,.06);
}

.sidebar-section-label {
    color: rgba(195,196,199,.5);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
    padding: 0 16px 6px;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 16px;
    color: var(--color-sidebar-text);
    font-size: 13px;
    text-decoration: none;
    border-left: 3px solid transparent;
    transition: background .1s, color .1s;
    position: relative;
}

/* Hide bare text labels when collapsed (labels may not be in <span>) */
.sidebar.is-collapsed .sidebar-link {
    justify-content: center;
    padding: 10px 0;
    font-size: 0; /* hide text nodes next to icons */
    width: 100%;
    height: auto;
    min-height: 40px;
    border-left-width: 0;
    gap: 0;
}

.sidebar.is-collapsed .sidebar-link span:not(.sr-only) {
    display: none;
}

.sidebar.is-collapsed .sidebar-link svg {
    margin: 0;
    font-size: 16px;
    width: 16px;
    height: 16px;
    display: block;
    flex-shrink: 0;
}

.sidebar-link:hover {
    background: var(--color-sidebar-hover);
    color: #fff;
    text-decoration: none;
}

.sidebar-link.is-active {
    background: var(--color-sidebar-hover);
    color: #fff;
    border-left-color: var(--color-brand);
}

.sidebar-link svg { flex-shrink: 0; opacity: .7; }
.sidebar-link.is-active svg, .sidebar-link:hover svg { opacity: 1; }

.sidebar-section-bottom { margin-top: auto; border-bottom: none; border-top: 1px solid rgba(255,255,255,.06); }
.sidebar-logout { color: rgba(195,196,199,.6); }
.sidebar-logout:hover { color: #fff; }

/* Main content — right column, no left margin (shell is flex row) */
.main-content {
    margin-left: 0;
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - var(--chrome-height));
    background: var(--color-bg);
}

/* collapsed sidebar is a sibling inside .app-shell — width only, no margin hack */
.app-shell .sidebar.is-collapsed + .main-content {
    /* flex absorbs remaining space */
}

/* ----------------------------------------------------------------
   App header (640) — full-width sticky bar above shell
---------------------------------------------------------------- */
.app-header {
    background: var(--color-header-bg, #0f172a);
    color: #fff;
    padding: 0 16px 0 20px;
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 300;
    flex-shrink: 0;
    width: 100%;
    box-sizing: border-box;
}

.app-header-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    flex-shrink: 1;
}

.header-logo {
    max-height: 34px;
    border-radius: 4px;
}

.header-business-name {
    font-size: 0.95rem;
    font-weight: 800;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 260px;
    margin: 0;
}

.app-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    margin-left: auto;
    flex-wrap: nowrap;
    position: relative;
}

.hdr-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(255,255,255,.08);
    border: 1px solid rgba(255,255,255,.16);
    color: rgba(255,255,255,.85);
    border-radius: 5px;
    padding: 4px 10px;
    font-size: 0.72rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    line-height: 1.3;
}
.hdr-btn:hover { background: rgba(255,255,255,.14); color: #fff; text-decoration: none; }

.hdr-search-btn {
    border-radius: 16px;
    padding: 4px 12px;
    color: rgba(255,255,255,.72);
}

.hdr-icon-btn {
    position: relative;
    background: none;
    border: none;
    color: rgba(255,255,255,.8);
    cursor: pointer;
    padding: 4px 6px;
    line-height: 0;
    border-radius: 6px;
}
.hdr-icon-btn:hover { background: rgba(255,255,255,.08); color: #fff; }

.hdr-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #cf222e;
    color: #fff;
    font-size: 9px;
    font-weight: 700;
    min-width: 16px;
    height: 16px;
    border-radius: 8px;
    line-height: 16px;
    text-align: center;
    padding: 0 2px;
}

.hdr-sep {
    width: 1px;
    height: 22px;
    background: rgba(255,255,255,.15);
    display: inline-block;
    flex-shrink: 0;
}

.version-badge {
    font-size: 0.68rem;
    font-weight: 700;
    color: rgba(147,197,253,.85);
    background: rgba(147,197,253,.1);
    border: 1px solid rgba(147,197,253,.2);
    border-radius: 4px;
    padding: 2px 7px;
    letter-spacing: .03em;
    white-space: nowrap;
}

.hdr-lang-form { margin: 0; }
.hdr-lang-sel {
    background: rgba(255,255,255,.07);
    border: 1px solid rgba(255,255,255,.15);
    color: rgba(255,255,255,.85);
    border-radius: 5px;
    padding: 3px 5px;
    font-size: 0.7rem;
    cursor: pointer;
    font-family: inherit;
    max-width: 140px;
}
.hdr-lang-sel option { color: #0f172a; background: #fff; }

.hdr-user {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    line-height: 1.3;
    max-width: 180px;
    min-width: 0;
    overflow: hidden;
    padding: 0 4px;
}
.hdr-user-name {
    font-size: 0.78rem;
    font-weight: 700;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}
.hdr-user-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    max-width: 100%;
}
.hdr-role-badge {
    font-size: 0.62rem;
    font-weight: 700;
    color: #93c5fd;
    background: rgba(147,197,253,.12);
    border: 1px solid rgba(147,197,253,.28);
    border-radius: 999px;
    padding: 0 6px;
    white-space: nowrap;
}
.hdr-user-email {
    font-size: 0.65rem;
    color: rgba(255,255,255,.45);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 110px;
}

.hdr-logout-btn {
    background: rgba(239,68,68,.15);
    border-color: rgba(239,68,68,.35);
    color: rgba(255,200,200,.95);
    font-weight: 700;
}
.hdr-logout-btn:hover { background: rgba(239,68,68,.28); color: #fff; }
.hdr-logout-form { margin: 0; display: inline; }

.hdr-dev-btn {
    color: #fbbf24;
    border-color: rgba(251,191,36,.35);
    background: rgba(251,191,36,.1);
}
.hdr-dev-wrap { position: relative; }

.hdr-shop-btn {
    color: #93c5fd;
    border-color: rgba(147,197,253,.28);
    background: rgba(147,197,253,.12);
}
.hdr-shop-btn:hover { background: rgba(147,197,253,.22); color: #fff; }

.plan-badge {
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: .02em;
    border-radius: 999px;
    padding: 3px 10px;
    white-space: nowrap;
    border: 1px solid transparent;
}
.plan-badge.is-free {
    color: rgba(255,255,255,.85);
    background: rgba(255,255,255,.1);
    border-color: rgba(255,255,255,.18);
}
.plan-badge.is-paid {
    color: #0f172a;
    background: linear-gradient(135deg, #fbbf24, #f59e0b);
    border-color: rgba(251,191,36,.5);
}

/* Sync status — full-width strip under header (still chrome, above sidebar) */
.sync-status {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 20px;
    font-size: 0.7rem;
    font-weight: 600;
    background: #0b1220;
    color: rgba(255,255,255,.65);
    border-bottom: 1px solid rgba(255,255,255,.06);
    min-height: var(--sync-height);
    height: var(--sync-height);
    box-sizing: border-box;
    position: sticky;
    top: var(--header-height);
    z-index: 290;
    flex-shrink: 0;
    width: 100%;
}
.sync-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #64748b;
    flex-shrink: 0;
    box-shadow: 0 0 0 2px rgba(100,116,139,.25);
}
.sync-status.is-ok .sync-dot { background: #22c55e; box-shadow: 0 0 0 2px rgba(34,197,94,.25); }
.sync-status.is-warn .sync-dot { background: #f59e0b; box-shadow: 0 0 0 2px rgba(245,158,11,.25); }
.sync-status.is-error .sync-dot { background: #ef4444; box-shadow: 0 0 0 2px rgba(239,68,68,.25); }
.sync-status.is-ok #sync-label { color: #86efac; }
.sync-status.is-warn #sync-label { color: #fcd34d; }
.sync-status.is-error #sync-label { color: #fca5a5; }
.sync-counts {
    margin-left: auto;
    display: flex;
    gap: 10px;
    color: rgba(255,255,255,.45);
    font-variant-numeric: tabular-nums;
}

.hdr-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 180px;
    background: #1e293b;
    border: 1px solid rgba(255,255,255,.12);
    border-radius: 8px;
    box-shadow: 0 12px 28px rgba(0,0,0,.35);
    z-index: 200;
    padding: 6px 0;
    overflow: hidden;
}
.hdr-dropdown a,
.hdr-dropdown button {
    display: block;
    width: 100%;
    text-align: left;
    padding: 8px 14px;
    font-size: 0.8rem;
    color: rgba(255,255,255,.88);
    background: none;
    border: none;
    cursor: pointer;
    font-family: inherit;
    text-decoration: none;
}
.hdr-dropdown a:hover,
.hdr-dropdown button:hover { background: rgba(255,255,255,.08); color: #fff; }
.hdr-dropdown-empty {
    padding: 12px 14px;
    font-size: 0.78rem;
    color: rgba(255,255,255,.5);
}
.hdr-dropdown-link {
    border-top: 1px solid rgba(255,255,255,.08) !important;
    font-weight: 600;
}
#notif-panel.notif-panel,
.notif-panel {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 320px;
    max-width: min(380px, calc(100vw - 24px));
    max-height: min(70vh, 420px);
    display: flex;
    flex-direction: column;
    padding: 0;
    overflow: hidden;
}
.notif-panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 12px 8px;
    border-bottom: 1px solid rgba(255,255,255,.08);
}
.notif-panel-title {
    font-size: 0.8rem;
    font-weight: 700;
    color: rgba(255,255,255,.92);
}
.notif-mark-read {
    font-size: 0.72rem !important;
    font-weight: 600;
    color: #93c5fd !important;
    background: none;
    border: none;
    cursor: pointer;
    padding: 2px 6px !important;
    width: auto !important;
}
.notif-mark-read:hover { color: #fff !important; text-decoration: underline; }
.notif-panel-list {
    overflow-y: auto;
    max-height: 320px;
    flex: 1 1 auto;
}
.notif-item {
    display: flex !important;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 12px !important;
    text-decoration: none;
    color: rgba(255,255,255,.9) !important;
    border-bottom: 1px solid rgba(255,255,255,.06);
    width: 100%;
    box-sizing: border-box;
}
.notif-item:last-child { border-bottom: none; }
.notif-item.is-unread { background: rgba(59, 130, 246, 0.12); }
.notif-item:hover { background: rgba(255,255,255,.08) !important; color: #fff !important; }
.notif-item-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
}
.notif-item-body {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    flex: 1;
}
.notif-item-title {
    font-size: 0.8rem;
    font-weight: 600;
    line-height: 1.3;
}
.notif-item.is-unread .notif-item-title { font-weight: 700; }
.notif-item-text {
    font-size: 0.72rem;
    color: rgba(255,255,255,.55);
    line-height: 1.35;
    white-space: normal;
    word-break: break-word;
}
.notif-item-time {
    font-size: 0.68rem;
    color: rgba(255,255,255,.4);
    margin-top: 2px;
}
.notif-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #3b82f6;
    margin-left: 6px;
    vertical-align: middle;
}

.page-title-bar {
    background: var(--color-bg-card);
    border-bottom: 1px solid var(--color-border);
    padding: 12px 24px;
}
.page-title {
    font-size: 18px;
    font-weight: 600;
    margin: 0;
}

/* Legacy light page-header (content pages that still use the class) */
.page-header {
    background: var(--color-bg-card);
    border-bottom: 1px solid var(--color-border);
    padding: 12px 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
}
.page-header-user {
    display: flex;
    align-items: center;
    gap: 8px;
}
.user-name { font-weight: 500; }
.user-role {
    background: var(--color-brand-light);
    color: var(--color-brand);
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
}

/* Global search overlay */
.global-search-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,.45);
    z-index: 400;
    display: none;
    align-items: flex-start;
    justify-content: center;
    padding-top: 12vh;
}
.global-search-box {
    width: min(520px, 92vw);
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 20px 50px rgba(0,0,0,.25);
    overflow: hidden;
}
.global-search-input {
    width: 100%;
    border: none;
    border-bottom: 1px solid var(--color-border);
    padding: 14px 16px;
    font-size: 1rem;
    outline: none;
}
.global-search-results { max-height: 320px; overflow-y: auto; }
.gs-item {
    display: block;
    padding: 10px 16px;
    font-size: 0.9rem;
    color: #0f172a;
    text-decoration: none;
    border-bottom: 1px solid rgba(0,0,0,.04);
}
.gs-item:hover, .gs-item.is-first { background: #eff6ff; }
.gs-sub { display: block; font-size: 0.75rem; color: #64748b; margin-top: 2px; }
.gs-empty { padding: 14px 16px; color: #94a3b8; font-size: 0.85rem; }
.global-search-hint {
    padding: 8px 16px;
    font-size: 0.7rem;
    color: #94a3b8;
    background: #f8fafc;
    border-top: 1px solid var(--color-border);
}

/* Header control always available to expand nav if rail is hard to find */
.hdr-nav-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    min-height: 36px;
}

@media (max-width: 900px) {
    .hdr-user-email,
    .hdr-sep,
    .hdr-search-btn span { display: none; }
    .header-business-name { max-width: 140px; }
    .hdr-lang-sel { max-width: 72px; }

    /* Icon rail on narrow screens — still keep toggle usable */
    .sidebar {
        width: 56px;
        min-width: 56px;
        top: var(--chrome-height);
        height: calc(100vh - var(--chrome-height));
        max-height: calc(100vh - var(--chrome-height));
    }
    .sidebar:not(.is-collapsed) {
        width: min(220px, 78vw);
        min-width: 0;
        position: fixed;
        left: 0;
        z-index: 200;
        box-shadow: 4px 0 24px rgba(0,0,0,.25);
    }
    .sidebar-section-label,
    .sidebar .brand-name { display: none; }
    .sidebar:not(.is-collapsed) .sidebar-section-label,
    .sidebar:not(.is-collapsed) .brand-name { display: block; }
    .sidebar .sidebar-link span:not(.sr-only) { display: none; }
    .sidebar:not(.is-collapsed) .sidebar-link span:not(.sr-only) { display: inline; }
    .sidebar:not(.is-collapsed) .sidebar-link { font-size: 13px; }
}

.page-body {
    padding: 24px;
    flex: 1;
}

/* ----------------------------------------------------------------
   Alerts / flash messages
---------------------------------------------------------------- */
.alert {
    padding: 10px 16px;
    border-radius: var(--radius);
    margin: 0 24px 0;
    font-size: 14px;
    border-left: 4px solid;
}

.alert + .page-body { padding-top: 16px; }
.alert { margin-bottom: 0; }

.page-header + .alert { margin-top: 12px; }

.alert-success {
    background: var(--color-success-bg);
    border-color: var(--color-success);
    color: #1a6b2a;
}

.alert-error {
    background: var(--color-danger-bg);
    border-color: var(--color-danger);
    color: #9e2122;
}

.alert-warning {
    background: var(--color-warning-bg);
    border-color: var(--color-warning);
    color: #664d00;
}

/* ----------------------------------------------------------------
   Cards
---------------------------------------------------------------- */
.card {
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.card-header {
    padding: 14px 20px;
    border-bottom: 1px solid var(--color-border);
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-body { padding: 20px; }

/* Summary / stat cards */
.stat-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 18px 20px;
    box-shadow: var(--shadow-sm);
}

.stat-label {
    font-size: 12px;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: .5px;
    margin-bottom: 6px;
}

.stat-value {
    font-size: 24px;
    font-weight: 700;
    line-height: 1;
}

.stat-value.positive { color: var(--color-success); }
.stat-value.negative { color: var(--color-danger); }

/* ----------------------------------------------------------------
   Tables
---------------------------------------------------------------- */
.table-wrap {
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th {
    background: #f6f7f7;
    padding: 10px 16px;
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: .4px;
    border-bottom: 1px solid var(--color-border);
    white-space: nowrap;
}

.data-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--color-border);
    vertical-align: middle;
}

.data-table tr:last-child td { border-bottom: none; }

.data-table tbody tr:hover { background: #f9f9f9; }

.table-empty {
    text-align: center;
    color: var(--color-text-muted);
    padding: 40px 16px;
}

/* ----------------------------------------------------------------
   Status badges
---------------------------------------------------------------- */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    border-radius: 10px;
    font-size: 12px;
    font-weight: 500;
}

.badge-draft     { background: #f0f0f1; color: #50575e; }
.badge-sent      { background: #e8f1f8; color: var(--color-brand); }
.badge-partial   { background: #fcf9e8; color: var(--color-warning); }
.badge-paid      { background: var(--color-success-bg); color: var(--color-success); }
.badge-overdue   { background: var(--color-danger-bg); color: var(--color-danger); }
.badge-cancelled { background: #f0f0f1; color: var(--color-text-muted); }

/* ----------------------------------------------------------------
   Forms
---------------------------------------------------------------- */
.field { margin-bottom: 16px; }

.field label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 5px;
}

.field input[type="text"],
.field input[type="email"],
.field input[type="number"],
.field input[type="date"],
.field input[type="password"],
.field select,
.field textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: #fff;
    color: var(--color-text);
    font-size: 14px;
    transition: border-color .15s;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
    outline: none;
    border-color: var(--color-brand);
    box-shadow: 0 0 0 2px rgba(34, 113, 177, .15);
}

.field-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 16px;
}

.field-inline {
    display: flex;
    align-items: center;
    gap: 8px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 13px;
}

.field-hint {
    font-size: 12px;
    color: var(--color-text-muted);
    margin-top: 4px;
}

/* ----------------------------------------------------------------
   Buttons
---------------------------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 16px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: background .15s, border-color .15s, color .15s;
    line-height: 1.4;
}

.btn-primary {
    background: var(--color-brand);
    color: #fff;
    border-color: var(--color-brand);
}
.btn-primary:hover {
    background: var(--color-brand-dark);
    border-color: var(--color-brand-dark);
    color: #fff;
    text-decoration: none;
}

.btn-secondary {
    background: #fff;
    color: var(--color-text);
    border-color: var(--color-border);
}
.btn-secondary:hover {
    background: #f6f7f7;
    text-decoration: none;
}

.btn-danger {
    background: var(--color-danger);
    color: #fff;
    border-color: var(--color-danger);
}
.btn-danger:hover { background: #a02222; text-decoration: none; }

.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; }

/* ----------------------------------------------------------------
   Page toolbar (top of list pages)
---------------------------------------------------------------- */
.page-toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.page-toolbar-end { margin-left: auto; }

.search-input {
    padding: 7px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 13px;
    width: 240px;
}

/* ----------------------------------------------------------------
   Pagination
---------------------------------------------------------------- */
.pagination {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 16px;
}

.pagination a, .pagination span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: var(--radius);
    font-size: 13px;
    border: 1px solid var(--color-border);
    text-decoration: none;
    color: var(--color-text);
}

.pagination a:hover { background: var(--color-brand-light); border-color: var(--color-brand); }
.pagination .current { background: var(--color-brand); color: #fff; border-color: var(--color-brand); }

/* ----------------------------------------------------------------
   Dashboard chart area
---------------------------------------------------------------- */
.chart-card {
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: var(--shadow-sm);
    margin-bottom: 24px;
}

.chart-card h3 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: .4px;
}

/* ----------------------------------------------------------------
   Utilities
---------------------------------------------------------------- */
.text-right  { text-align: right; }
.text-center { text-align: center; }
.text-muted  { color: var(--color-text-muted); }
.text-success { color: var(--color-success); }
.text-danger  { color: var(--color-danger); }
.text-sm     { font-size: 12px; }
.font-mono   { font-family: var(--font-mono); }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.gap-2 { gap: 16px; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 24px; }

@media (max-width: 900px) {
    .grid-2, .grid-3 { grid-template-columns: 1fr; }
}
