/* =====================================================================
   BI-bee — Style
   ===================================================================== */

*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg:            #FFFCF5;
    --card-bg:       #FFFFFF;
    --card-border:   #F0DFB8;
    --accent:        #F5A623;
    --accent-hover:  #E09415;
    --accent-dim:    rgba(245, 166, 35, 0.10);
    --text-primary:  #2D2006;
    --text-secondary:#6B5B3E;
    --text-muted:    #A8956F;
    --green:         #4CAF50;
    --red:           #E53935;
    --surface:       #FFFFFF;
    --shopify:       #96bf48;
    --etsy:          #f1641e;
    --amazon:        #ff9900;
    --manual:        #7b8794;
    --font-mono:     'DM Mono', monospace;
    --font-sans:     'Assistant', sans-serif;
}

html {
    font-size: 15px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    background: var(--bg);
    color: var(--text-primary);
    font-family: var(--font-sans);
    line-height: 1.5;
    min-height: 100vh;
}

/* =====================================================================
   AUTH SCREENS
   ===================================================================== */

.auth-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg);
    padding: 24px;
}

.auth-box {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    padding: 40px;
    max-width: 400px;
    width: 100%;
    box-shadow: 0 4px 24px rgba(45, 32, 6, 0.06);
}

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

.auth-logo svg {
    width: 32px;
    height: 32px;
}

.auth-logo-text {
    font-family: var(--font-sans);
    font-weight: 700;
    font-size: 1.5rem;
    color: var(--accent);
    letter-spacing: 0.02em;
}

.auth-subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 28px;
}

.auth-label {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-secondary);
    display: block;
    margin-bottom: 4px;
}

.auth-input {
    width: 100%;
    padding: 10px 12px;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    border: 1px solid var(--card-border);
    border-radius: 6px;
    background: var(--bg);
    color: var(--text-primary);
    margin-bottom: 14px;
    outline: none;
    transition: border-color 0.15s;
}

.auth-input:focus {
    border-color: var(--accent);
}

.auth-btn {
    width: 100%;
    padding: 12px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 6px;
    font-family: var(--font-sans);
    font-weight: 700;
    font-size: 0.95rem;
    cursor: pointer;
    transition: background 0.15s;
    margin-top: 4px;
}

.auth-btn:hover {
    background: var(--accent-hover);
}

.auth-error {
    color: var(--red);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    margin-bottom: 12px;
    display: none;
}
.auth-success {
    color: var(--green, #4ade80);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    margin-bottom: 12px;
    display: none;
}

.auth-link {
    display: block;
    text-align: center;
    margin-top: 18px;
    font-size: 0.82rem;
    color: var(--text-muted);
}

.auth-link a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
}

.auth-link a:hover {
    text-decoration: underline;
}

.auth-footer-links {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid var(--card-border);
}

.auth-footer-links a {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-decoration: none;
}

.auth-footer-links a:hover {
    color: var(--accent);
}

.auth-logo,
.auth-logo:hover,
.auth-logo:visited {
    text-decoration: none;
    color: inherit;
}

/* =====================================================================
   LAYOUT
   ===================================================================== */

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 24px 24px;
}

/* =====================================================================
   APP FOOTER
   ===================================================================== */

.app-footer {
    border-top: 1px solid var(--card-border);
    padding: 24px 0;
    margin-top: 48px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
}

.app-footer-copy {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    color: var(--text-muted);
}

.app-footer-links {
    display: flex;
    gap: 20px;
}

.app-footer-link {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    color: var(--text-muted);
    text-decoration: none;
    transition: color 0.15s;
}

/* =====================================================================
   PAYWALL OVERLAY
   ===================================================================== */

.paywall-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(255, 252, 245, 0.82);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.paywall-box {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    padding: 48px 40px;
    max-width: 440px;
    width: 100%;
    text-align: center;
    box-shadow: 0 8px 40px rgba(45, 32, 6, 0.12);
}

.paywall-title {
    font-family: var(--font-sans);
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.paywall-text {
    font-size: 0.88rem;
    color: var(--text-secondary);
    margin-bottom: 20px;
    line-height: 1.5;
}

.paywall-price {
    font-family: var(--font-mono);
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 24px;
}

.paywall-btn-wrap {
    min-height: 55px;
    margin-bottom: 16px;
}

.paywall-logout {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.82rem;
    cursor: pointer;
    text-decoration: underline;
    margin-top: 8px;
}

.app-footer-link:hover {
    color: var(--accent);
}

/* =====================================================================
   HEADER
   ===================================================================== */

.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 24px 0 20px;
    border-bottom: 1px solid var(--card-border);
    margin-bottom: 28px;
    flex-wrap: wrap;
    gap: 16px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-logo,
.header-logo:hover,
.header-logo:visited {
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    color: inherit;
}

.header-logo svg {
    width: 28px;
    height: 28px;
}

.header-logo-text {
    font-family: var(--font-sans);
    font-weight: 700;
    font-size: 1.3rem;
    color: var(--accent);
    letter-spacing: 0.02em;
}

.header-subtitle {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-weight: 400;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    margin-left: 4px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
}

.header-user {
    display: flex;
    align-items: center;
    gap: 10px;
    font-family: var(--font-mono);
    font-size: 0.72rem;
    color: var(--text-muted);
}

.header-user-email {
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.btn-logout {
    background: none;
    border: 1px solid var(--card-border);
    border-radius: 4px;
    color: var(--text-muted);
    padding: 4px 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    transition: all 0.15s;
}

.btn-logout:hover {
    border-color: var(--red);
    color: var(--red);
}

.period-buttons {
    display: flex;
    gap: 2px;
}

.period-btn {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    font-weight: 500;
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--card-border);
    border-radius: 4px;
    padding: 6px 14px;
    cursor: pointer;
    letter-spacing: 0.02em;
    transition: all 0.15s;
}

.period-btn:hover {
    color: var(--text-secondary);
    border-color: var(--accent);
}

.period-btn.active {
    background: var(--accent);
    color: #ffffff;
    border-color: var(--accent);
}

.period-custom-wrap {
    position: relative;
}

.period-custom-popover {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    padding: 12px 14px;
    box-shadow: 0 8px 24px rgba(45, 32, 6, 0.12);
    z-index: 30;
    min-width: 180px;
}

.period-custom-label {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    color: var(--text-muted);
    letter-spacing: 0.03em;
}

.period-custom-input {
    font-family: var(--font-mono);
    font-size: 0.82rem;
    border: 1px solid var(--card-border);
    border-radius: 4px;
    padding: 5px 8px;
    background: var(--bg);
    color: var(--text-primary);
    width: 100%;
    box-sizing: border-box;
}

.period-custom-apply {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    font-weight: 600;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 4px;
    padding: 6px 12px;
    cursor: pointer;
    margin-top: 4px;
}

.period-custom-apply:hover {
    opacity: 0.9;
}

/* =====================================================================
   FILTER BAR
   ===================================================================== */
.filter-bar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 10px 0;
    flex-wrap: wrap;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

.filter-label {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.filter-select-wrap {
    position: relative;
}

.filter-select-btn {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    background: var(--card-bg);
    color: var(--text-secondary);
    border: 1px solid var(--card-border);
    border-radius: 4px;
    padding: 5px 28px 5px 10px;
    cursor: pointer;
    white-space: nowrap;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: border-color 0.15s;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23A8956F' stroke-width='1.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
}

.filter-select-btn:hover {
    border-color: var(--accent);
}

.filter-select-btn.filter-active {
    background: var(--accent-dim);
    border-color: var(--accent);
    color: var(--text-primary);
    font-weight: 600;
}

.filter-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    min-width: 180px;
    max-height: 260px;
    overflow-y: auto;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(45, 32, 6, 0.12);
    z-index: 40;
    padding: 4px 0;
}

.filter-dropdown-wide {
    min-width: 260px;
}

.filter-dropdown-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    font-family: var(--font-mono);
    font-size: 0.78rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.1s;
}

.filter-dropdown-item:hover {
    background: var(--accent-dim);
}

.filter-dropdown-item.selected {
    color: var(--text-primary);
    font-weight: 600;
}

.filter-dropdown-item input[type="checkbox"] {
    accent-color: var(--accent);
    width: 14px;
    height: 14px;
    cursor: pointer;
}

.filter-reset-btn {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    color: var(--accent);
    background: none;
    border: none;
    cursor: pointer;
    padding: 5px 0;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.filter-reset-btn:hover {
    color: var(--text-primary);
}

/* =====================================================================
   SETTINGS TOGGLE (Brutto/Netto)
   ===================================================================== */
.settings-toggle-wrap {
    display: flex;
    gap: 0;
    border: 1px solid var(--card-border);
    border-radius: 4px;
    overflow: hidden;
}

.settings-toggle-btn {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    padding: 5px 14px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s;
}

.settings-toggle-btn.active {
    background: var(--accent);
    color: #fff;
}

.settings-toggle-btn:hover:not(.active) {
    background: var(--accent-dim);
    color: var(--text-secondary);
}

/* =====================================================================
   PRODUCT GROUPS MODAL
   ===================================================================== */
.pg-modal-box {
    max-width: 820px;
    width: 95vw;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
}

.pg-subtitle {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin: 0 0 12px 0;
}

.pg-content {
    flex: 1;
    overflow-y: auto;
    padding-bottom: 8px;
}

.pg-groups-area {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 12px;
    min-height: 0;
}

.pg-divider-label {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 6px;
    margin-top: 4px;
    padding-top: 8px;
    border-top: 1px solid var(--card-border);
}

.pg-ungrouped-area {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-height: 60px;
}

/* Group card */
.pg-group {
    background: var(--bg);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    padding: 8px 10px;
}

.pg-group.drag-over {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(245, 166, 35, 0.2);
}

.pg-group-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.pg-group-name {
    flex: 1;
    font-family: var(--font-mono);
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-primary);
    background: transparent;
    border: none;
    border-bottom: 1px solid transparent;
    padding: 2px 0;
    outline: none;
}

.pg-group-name:focus {
    border-color: var(--accent);
}

.pg-group-delete {
    background: none;
    border: none;
    font-size: 1rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px 4px;
    line-height: 1;
}

.pg-group-delete:hover {
    color: var(--red);
}

.pg-group-tiles {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-height: 44px;
}

/* Product tile */
.pg-tile {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 6px;
    padding: 7px 10px;
    cursor: grab;
    user-select: none;
    transition: box-shadow 0.15s, border-color 0.15s;
    width: 100%;
    box-sizing: border-box;
}

.pg-tile:active {
    cursor: grabbing;
}

.pg-tile.dragging {
    opacity: 0.4;
}

.pg-tile.drag-over {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(245, 166, 35, 0.25);
}

.pg-tile-img {
    width: 36px;
    height: 36px;
    border-radius: 4px;
    object-fit: cover;
    background: var(--bg);
    flex-shrink: 0;
}

.pg-tile-img-placeholder {
    width: 36px;
    height: 36px;
    border-radius: 4px;
    background: var(--accent-dim);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 0.7rem;
}

.pg-tile-info {
    min-width: 0;
    flex: 1;
}

.pg-tile-title {
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--text-primary);
    line-height: 1.3;
}

.pg-tile-sku {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    color: var(--text-muted);
}

.pg-tile-edit {
    flex-shrink: 0;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    line-height: 1;
    opacity: 0;
    transition: opacity 0.15s;
}

.pg-tile:hover .pg-tile-edit {
    opacity: 1;
}

.pg-tile-edit:hover {
    color: var(--accent);
    background: var(--accent-dim);
}

/* =====================================================================
   BILLING FORM
   ===================================================================== */
.settings-billing-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.settings-billing-row-split {
    display: flex;
    gap: 10px;
}

/* =====================================================================
   CHART GROUPING DROPDOWN (inline in title)
   ===================================================================== */
.chart-grouping-select {
    font-family: var(--font-mono);
    font-size: inherit;
    font-weight: 600;
    color: var(--accent);
    background: transparent;
    border: none;
    border-bottom: 1px dashed var(--accent);
    cursor: pointer;
    padding: 0 2px;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
}

.chart-grouping-select:hover {
    border-bottom-style: solid;
}

.chart-grouping-select option {
    font-family: var(--font-mono);
    color: var(--text-primary);
    background: var(--card-bg);
}

/* Cart metric select — only visible in edit mode */
.cart-metric-select {
    display: none;
    font-family: var(--font-mono);
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--accent);
    background: transparent;
    border: 1px dashed var(--accent);
    border-radius: 4px;
    cursor: pointer;
    padding: 1px 4px;
    margin-left: 6px;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
}

.dashboard-editing .cart-metric-select {
    display: inline-block;
}

.cart-metric-select:hover {
    background: var(--accent-dim);
}

.cart-metric-select option {
    font-family: var(--font-mono);
    color: var(--text-primary);
    background: var(--card-bg);
}

.sync-status {
    position: relative;
    display: flex;
    align-items: center;
    cursor: default;
}

.sync-text {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    font-family: var(--font-mono);
    font-size: 0.72rem;
    color: var(--text-muted);
    letter-spacing: 0.01em;
    white-space: nowrap;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 6px;
    padding: 4px 10px;
    box-shadow: 0 4px 16px rgba(45, 32, 6, 0.08);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s;
    z-index: 20;
}

.sync-status:hover .sync-text,
.sync-status.syncing .sync-text {
    opacity: 1;
}

.sync-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}

.sync-dot.ok { background: var(--green); }
.sync-dot.err { background: var(--red); }
.sync-dot.syncing {
    background: var(--accent);
    animation: syncPulse 1s ease-in-out infinite;
}

@keyframes syncPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* =====================================================================
   CARDS / GRID
   ===================================================================== */

.card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 10px;
    padding: 24px;
    box-shadow: 0 1px 4px rgba(45, 32, 6, 0.04);
}

.card-title {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--text-muted);
    letter-spacing: 0.1em;
    text-transform: uppercase;
    margin-bottom: 14px;
}

.card-title-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 18px;
}

.card-title-row .card-title { margin-bottom: 0; }

.card-title-sum {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.kpi-container {
    display: flex;
    flex-direction: column;
}

.grid-kpi {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
    margin-bottom: 12px;
}

/* Row drop zones — appear between KPI rows during drag */
.kpi-row-dropzone {
    height: 6px;
    margin: 2px 0;
    border-radius: 3px;
    background: transparent;
    transition: height 0.15s ease, background 0.15s ease, margin 0.15s ease;
}

.kpi-row-dropzone.dropzone-active {
    height: 32px;
    margin: 6px 0;
    background: var(--accent-dim);
    border: 2px dashed var(--accent);
    border-radius: 8px;
}

.grid-2col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 12px;
}

.full-width { margin-bottom: 12px; }

/* =====================================================================
   KPI CARDS
   ===================================================================== */

.kpi-value {
    font-family: var(--font-mono);
    font-size: 1.9rem;
    font-weight: 500;
    color: var(--text-primary);
    line-height: 1.2;
    margin-bottom: 8px;
}

.kpi-changes {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.kpi-change {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    font-weight: 400;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.kpi-change.positive { color: var(--green); }
.kpi-change.negative { color: var(--red); }
.kpi-change.neutral { color: var(--text-muted); }

.kpi-change-label {
    font-family: var(--font-sans);
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-left: 6px;
}

/* =====================================================================
   CHARTS
   ===================================================================== */

.chart-wrap { position: relative; width: 100%; }
.chart-wrap.revenue-chart { height: 300px; }
.chart-wrap.donut-chart { height: 300px; }
.chart-wrap.bar-chart { height: 300px; }
.chart-wrap.stacked-chart { height: 320px; }
.chart-wrap canvas { width: 100% !important; height: 100% !important; }

/* =====================================================================
   TABLE
   ===================================================================== */

.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.products-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}

.products-table th {
    font-family: var(--font-mono);
    font-size: 0.68rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    text-align: left;
    padding: 10px 12px;
    border-bottom: 1px solid var(--card-border);
    white-space: nowrap;
}

.products-table th.num { text-align: right; }

.products-table td {
    padding: 10px 12px;
    border-bottom: 1px solid rgba(240, 223, 184, 0.5);
    vertical-align: middle;
}

.products-table tr:nth-child(even) td {
    background: rgba(245, 166, 35, 0.03);
}

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

.products-table .col-rank {
    font-family: var(--font-mono);
    color: var(--text-muted);
    font-size: 0.75rem;
    width: 36px;
}

.products-table .col-product {
    color: var(--text-primary);
    font-weight: 400;
    max-width: 320px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.product-link {
    color: var(--text-primary);
    text-decoration: none;
    border-bottom: 1px dashed var(--card-border);
    transition: all 0.15s;
}

.product-link:hover {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.products-table .col-sku {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.products-table .col-num {
    font-family: var(--font-mono);
    text-align: right;
    white-space: nowrap;
    color: var(--text-secondary);
}

.products-table .col-revenue {
    width: 220px;
    min-width: 180px;
}

.revenue-cell {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
}

.revenue-bar-track {
    flex: 1;
    height: 4px;
    background: rgba(245, 166, 35, 0.12);
    border-radius: 2px;
    position: relative;
    min-width: 60px;
}

.revenue-bar-fill {
    position: absolute;
    top: 0; left: 0;
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    opacity: 0.6;
}

.revenue-value {
    font-family: var(--font-mono);
    font-size: 0.82rem;
    color: var(--text-primary);
    white-space: nowrap;
}

/* =====================================================================
   LOADING / EMPTY
   ===================================================================== */

.loading-state {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 0.78rem;
    letter-spacing: 0.04em;
}

/* =====================================================================
   SETTINGS BUTTON
   ===================================================================== */

.btn-settings {
    background: none;
    border: 1px solid var(--card-border);
    border-radius: 4px;
    color: var(--text-muted);
    padding: 4px 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    transition: all 0.15s;
}

.btn-settings:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* =====================================================================
   MODAL
   ===================================================================== */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(45, 32, 6, 0.4);
    backdrop-filter: blur(2px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.modal-box {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    padding: 0;
    max-width: 480px;
    width: 100%;
    box-shadow: 0 8px 40px rgba(45, 32, 6, 0.12);
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--card-border);
}

.modal-title {
    font-family: var(--font-sans);
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text-primary);
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.4rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

.modal-close:hover { color: var(--text-primary); }

.modal-section {
    padding: 24px;
}

.modal-section-title {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--text-muted);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    margin-bottom: 16px;
}

.settings-field {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid rgba(240, 223, 184, 0.4);
}

.settings-label {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-muted);
}

.settings-value {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--text-primary);
    max-width: 260px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.settings-actions {
    display: flex;
    gap: 8px;
    margin-top: 16px;
}

.btn-test {
    font-family: var(--font-sans);
    font-weight: 600;
    font-size: 0.82rem;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 8px 16px;
    cursor: pointer;
    transition: background 0.15s;
}

.btn-test:hover { background: var(--accent-hover); }
.btn-test:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-edit-creds, .btn-cancel {
    font-family: var(--font-sans);
    font-weight: 600;
    font-size: 0.82rem;
    background: none;
    color: var(--text-secondary);
    border: 1px solid var(--card-border);
    border-radius: 6px;
    padding: 8px 16px;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-edit-creds:hover, .btn-cancel:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.settings-test-result {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    padding: 8px 12px;
    border-radius: 6px;
    margin-top: 12px;
}

.settings-test-result.test-ok {
    background: rgba(76, 175, 80, 0.1);
    color: var(--green);
}

.settings-test-result.test-fail {
    background: rgba(229, 57, 53, 0.1);
    color: var(--red);
}

.settings-no-creds-text {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 16px;
}

.btn-cancel-sub {
    padding: 8px 20px;
    border: 1.5px solid #e74c3c;
    border-radius: 8px;
    background: transparent;
    color: #e74c3c;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.btn-cancel-sub:hover {
    background: #e74c3c;
    color: #fff;
}

.sub-status-active { color: #27ae60; font-weight: 600; }
.sub-status-trial { color: var(--primary); font-weight: 600; }
.sub-status-cancelled,
.sub-status-expired { color: #e74c3c; font-weight: 600; }
.sub-status-suspended { color: #f39c12; font-weight: 600; }

/* =====================================================================
   EDIT DASHBOARD BUTTON
   ===================================================================== */

.dashboard-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.dashboard-section-title {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--text-muted);
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.btn-edit-dashboard {
    background: none;
    border: 1px solid var(--card-border);
    border-radius: 4px;
    color: var(--text-muted);
    padding: 4px 10px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-family: var(--font-mono);
    font-size: 0.72rem;
    font-weight: 500;
    transition: all 0.15s;
    white-space: nowrap;
}

.btn-edit-dashboard:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* =====================================================================
   EDIT MODE TOOLBAR
   ===================================================================== */

.edit-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--card-bg);
    border: 2px dashed var(--accent);
    border-radius: 10px;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 12px;
}

.edit-toolbar-label {
    font-family: var(--font-mono);
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--accent);
    letter-spacing: 0.02em;
}

.edit-toolbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.edit-add-wrap {
    position: relative;
}

.btn-edit-add {
    font-family: var(--font-sans);
    font-weight: 600;
    font-size: 0.82rem;
    background: none;
    color: var(--accent);
    border: 1px solid var(--accent);
    border-radius: 6px;
    padding: 7px 14px;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-edit-add:hover {
    background: var(--accent-dim);
}

.btn-edit-reset {
    font-family: var(--font-sans);
    font-weight: 600;
    font-size: 0.82rem;
    background: none;
    color: var(--text-muted);
    border: 1px solid var(--card-border);
    border-radius: 6px;
    padding: 7px 14px;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-edit-reset:hover {
    border-color: var(--text-secondary);
    color: var(--text-secondary);
}

.btn-edit-done {
    font-family: var(--font-sans);
    font-weight: 700;
    font-size: 0.82rem;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 8px 18px;
    cursor: pointer;
    transition: background 0.15s;
}

.btn-edit-done:hover {
    background: var(--accent-hover);
}

/* Add popover */
.edit-add-popover {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 10px;
    box-shadow: 0 8px 32px rgba(45, 32, 6, 0.12);
    padding: 12px;
    min-width: 240px;
    max-height: 360px;
    overflow-y: auto;
    z-index: 100;
}

.edit-add-section {
    margin-bottom: 10px;
}

.edit-add-section:last-of-type {
    margin-bottom: 0;
}

.edit-add-title {
    font-family: var(--font-mono);
    font-size: 0.68rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 6px;
}

.edit-add-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.edit-add-item {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    color: var(--text-primary);
    background: var(--bg);
    border: 1px solid transparent;
    border-radius: 6px;
    padding: 7px 10px;
    cursor: pointer;
    transition: all 0.15s;
    text-align: left;
    width: 100%;
}

.edit-add-item:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.edit-add-empty {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    color: var(--text-muted);
    padding: 8px 0;
}

/* =====================================================================
   LIBRARY MODAL
   ===================================================================== */
.library-modal-box {
    max-width: 720px;
    width: 95vw;
}

.library-tabs {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--card-border);
    padding: 0 24px;
}

.library-tab {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-muted);
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    padding: 10px 16px;
    cursor: pointer;
    transition: all 0.15s;
}

.library-tab:hover {
    color: var(--text-primary);
}

.library-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.library-content {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    padding: 16px 24px 24px;
    max-height: 62vh;
    overflow-y: auto;
}

@media (min-width: 600px) {
    .library-content {
        grid-template-columns: repeat(3, 1fr);
    }
}

.library-content[data-tab="kpis"] .library-card {
    aspect-ratio: auto;
}

.library-content[data-tab="kpis"] .library-card-icon {
    height: 56px;
}

.library-card {
    display: flex;
    flex-direction: column;
    aspect-ratio: 4 / 3;
    padding: 0;
    border: 1px solid var(--card-border);
    border-radius: 10px;
    background: var(--bg);
    transition: all 0.15s;
    cursor: pointer;
    overflow: hidden;
    position: relative;
}

.library-card:hover {
    border-color: rgba(245, 166, 35, 0.4);
}

.library-card.active {
    border-color: var(--accent);
    background: rgba(245, 166, 35, 0.04);
}

.library-card-icon {
    flex-shrink: 0;
    width: 100%;
    height: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(245, 166, 35, 0.05);
    border-bottom: 1px solid var(--card-border);
}

.library-card-icon svg {
    display: block;
}

.library-card-body {
    flex: 1;
    padding: 10px 12px 8px;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.library-card-title {
    font-family: var(--font-mono);
    font-size: 0.74rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 3px;
    line-height: 1.2;
}

.library-card-desc {
    font-family: var(--font-body);
    font-size: 0.65rem;
    color: var(--text-muted);
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.library-card-toggle {
    position: absolute;
    top: 8px;
    right: 8px;
}

.library-toggle-btn {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 1.5px solid rgba(245, 166, 35, 0.25);
    background: rgba(255, 255, 255, 0.85);
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s;
}

.library-toggle-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.library-toggle-btn.is-active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.library-toggle-btn.is-active:hover {
    background: #e09520;
    border-color: #e09520;
}

/* =====================================================================
   EDIT MODE — CARD OVERLAYS
   ===================================================================== */

.dashboard-editing .card {
    position: relative;
    cursor: grab;
    transition: box-shadow 0.15s, border-color 0.15s;
}

.dashboard-editing .card:hover {
    border-color: var(--accent);
}

.dashboard-editing .card.dragging {
    opacity: 0.4;
    cursor: grabbing;
}

.dashboard-editing .card .edit-remove-btn {
    display: flex;
}

.edit-remove-btn {
    display: none;
    position: absolute;
    top: -8px;
    right: -8px;
    width: 22px;
    height: 22px;
    background: var(--red);
    color: #fff;
    border: 2px solid var(--card-bg);
    border-radius: 50%;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    z-index: 10;
    transition: transform 0.15s;
    padding: 0;
    font-family: var(--font-sans);
}

.edit-remove-btn:hover {
    transform: scale(1.2);
}

/* Drag over indicator */
.card.drag-over-before {
    box-shadow: -4px 0 0 0 var(--accent);
}

.card.drag-over-after {
    box-shadow: 4px 0 0 0 var(--accent);
}

.grid-kpi .card.drag-over-before {
    box-shadow: -4px 0 0 0 var(--accent);
}

.grid-kpi .card.drag-over-after {
    box-shadow: 4px 0 0 0 var(--accent);
}

/* Widget drag indicators — top/bottom for stacked layouts */
#widgetContainer .card.drag-over-before {
    box-shadow: 0 -4px 0 0 var(--accent);
}

#widgetContainer .card.drag-over-after {
    box-shadow: 0 4px 0 0 var(--accent);
}

/* =====================================================================
   RESPONSIVE
   ===================================================================== */

@media (max-width: 900px) {
    .grid-kpi { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
    .grid-2col { grid-template-columns: 1fr; }
    .header { flex-direction: column; align-items: flex-start; }
    .header-right { width: 100%; justify-content: flex-start; }
    .kpi-value { font-size: 1.5rem; }
    .chart-wrap.revenue-chart,
    .chart-wrap.donut-chart,
    .chart-wrap.bar-chart,
    .chart-wrap.stacked-chart { height: 250px; }
    .container { padding: 0 12px 48px; }
    .edit-toolbar { flex-direction: column; align-items: stretch; }
    .edit-toolbar-right { justify-content: flex-end; }
    .edit-add-popover { right: auto; left: 0; }
}

@media (max-width: 480px) {
    .grid-kpi { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 600px) {
    html { font-size: 14px; }
    .period-btn { padding: 5px 10px; font-size: 0.72rem; }
}

/* =====================================================================
   DEMO BANNER
   ===================================================================== */

.demo-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 18px;
    margin: 0 0 16px;
    background: linear-gradient(135deg, rgba(245, 166, 35, 0.12), rgba(245, 166, 35, 0.06));
    border: 1px solid rgba(245, 166, 35, 0.3);
    border-radius: 8px;
    font-size: 0.85rem;
    color: var(--text-primary);
}
.demo-banner-text {
    flex: 1;
}
.demo-banner-btn {
    flex-shrink: 0;
    padding: 6px 16px;
    background: var(--accent);
    color: #1a1a2e;
    border: none;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s;
}
.demo-banner-btn:hover {
    opacity: 0.85;
}

/* =====================================================================
   MFA / TOTP
   ===================================================================== */

.mfa-code-input {
    font-family: var(--font-mono);
    font-size: 1.75rem;
    letter-spacing: 0.5em;
    text-align: center;
    max-width: 260px;
    padding: 14px 16px 14px calc(16px + 0.25em);
    margin: 4px auto 14px;
    display: block;
}
.mfa-code-input::placeholder {
    letter-spacing: 0.5em;
    opacity: 0.3;
}

#mfaScreen .auth-subtitle,
#mfaScreen .auth-label,
#mfaScreen .auth-error,
#mfaScreen .auth-link {
    text-align: center;
}

.mfa-trust-label {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 0.82rem;
    color: var(--text-secondary);
    margin: 6px 0 14px;
    cursor: pointer;
    user-select: none;
}

.mfa-trust-label input[type="checkbox"] {
    accent-color: var(--accent);
    cursor: pointer;
}

#mfaScreen .auth-btn {
    margin: 0 auto;
    display: block;
}

.mfa-qr-wrap {
    display: flex;
    justify-content: center;
    margin: 16px 0;
}

.mfa-qr-wrap canvas {
    border: 1px solid var(--card-border);
    border-radius: 8px;
}

.mfa-secret-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    margin-bottom: 16px;
}

.mfa-secret-display code {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    background: var(--accent-dim);
    padding: 6px 12px;
    border-radius: 6px;
    letter-spacing: 0.15em;
    word-break: break-all;
    text-align: center;
}

.mfa-backup-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin: 12px 0;
}

.mfa-backup-code {
    font-family: var(--font-mono);
    font-size: 0.9rem;
    background: var(--bg);
    border: 1px solid var(--card-border);
    border-radius: 6px;
    padding: 8px;
    text-align: center;
    letter-spacing: 0.1em;
}

.mfa-status-active {
    color: var(--green);
    font-weight: 600;
}
