/* ============================================================
   RetailXchange PreSeason — Main Stylesheet
   Tenant colours are injected via :root CSS variables.
   ============================================================ */

/* Reset & Base */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; }

body {
    font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
    background: var(--color-bg, #F4F8F8);
    color: var(--color-accent, #2C3E50);
    line-height: 1.5;
    min-height: 100vh;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { color: var(--color-primary-hover); }

/* ── App Shell ─────────────────────────────────────────── */
.app-shell {
    display: grid;
    grid-template-columns: 240px 1fr;
    min-height: 100vh;
}

/* ── Sidebar ───────────────────────────────────────────── */
.sidebar {
    background: #ffffff;
    border-right: 1px solid #e8ecef;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.sidebar-logo {
    padding: 24px 20px 16px;
    border-bottom: 1px solid #f0f2f4;
}

.sidebar-logo img {
    max-width: 160px;
    max-height: 52px;
    object-fit: contain;
}

.sidebar-nav {
    flex: 1;
    padding: 12px 0;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px;
    color: #5a6474;
    font-size: 0.875rem;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
    border-left: 3px solid transparent;
}

.nav-item svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
    flex-shrink: 0;
}

.nav-item:hover {
    background: var(--color-bg);
    color: var(--color-primary);
}

.nav-item.active {
    background: var(--color-bg);
    color: var(--color-primary);
    border-left-color: var(--color-primary);
    font-weight: 600;
}

.nav-item--platform {
    font-size: 0.8rem;
    color: #8a929e;
}

.nav-divider {
    height: 1px;
    background: #f0f2f4;
    margin: 8px 20px;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 20px;
    border-top: 1px solid #f0f2f4;
    background: #fafbfc;
}

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

.user-name {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: #2c3e50;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-role {
    display: block;
    font-size: 0.72rem;
    color: #8a929e;
    text-transform: capitalize;
}

.btn-logout {
    color: #adb5bd;
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.btn-logout:hover { color: #e63946; }
.btn-logout svg { width: 18px; height: 18px; fill: currentColor; }

/* ── Main Content ──────────────────────────────────────── */
.main-content {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    overflow: hidden;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 32px 16px;
    background: #fff;
    border-bottom: 1px solid #e8ecef;
    gap: 16px;
}

.topbar-left { min-width: 0; }

.page-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--color-accent);
    line-height: 1.2;
}

.breadcrumb {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 4px;
    font-size: 0.8rem;
    color: #8a929e;
}

.breadcrumb a { color: var(--color-primary); }
.bc-sep { color: #c0c8d0; }

.topbar-right { display: flex; gap: 10px; flex-shrink: 0; }

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

/* ── Buttons ───────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 18px;
    border-radius: 7px;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: background 0.15s, transform 0.1s;
    white-space: nowrap;
}

.btn:active { transform: scale(0.98); }

.btn--primary {
    background: var(--color-primary);
    color: var(--color-text-on-primary, #fff);
}

.btn--primary:hover {
    background: var(--color-primary-hover);
    color: var(--color-text-on-primary, #fff);
}

.btn--secondary {
    background: #f0f2f4;
    color: var(--color-accent);
}

.btn--secondary:hover { background: #e4e8ec; }

.btn--danger { background: #e63946; color: #fff; }
.btn--danger:hover { background: #c1121f; }

.btn--sm { padding: 6px 14px; font-size: 0.8rem; }
.btn--full { width: 100%; justify-content: center; }

/* ── Cards ─────────────────────────────────────────────── */
.card {
    background: #fff;
    border-radius: 10px;
    border: 1px solid #e8ecef;
    overflow: hidden;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid #f0f2f4;
}

.card-title {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--color-accent);
}

.card-body { padding: 20px; }

/* ── Stat Cards ────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 28px;
}

.stat-card {
    background: #fff;
    border: 1px solid #e8ecef;
    border-radius: 10px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.stat-card__value {
    font-size: 2rem;
    font-weight: 800;
    color: var(--color-primary);
    line-height: 1;
}

.stat-card__label {
    font-size: 0.8rem;
    color: #8a929e;
    font-weight: 500;
}

/* ── Budget Bar ────────────────────────────────────────── */
.budget-bar {
    background: #f0f2f4;
    border-radius: 4px;
    height: 8px;
    overflow: hidden;
    margin-top: 6px;
}

.budget-bar__fill {
    height: 100%;
    background: var(--color-primary);
    border-radius: 4px;
    transition: width 0.3s ease;
}

.budget-bar__fill--warn  { background: #f4a261; }
.budget-bar__fill--over  { background: #e63946; }

/* ── Tables ────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; overflow-y: visible; }
/* Allow dropdowns in table cells to escape the table-wrap */
.table-wrap:has(.dropdown-menu[style*="block"]) { overflow: visible; }

table.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.data-table th {
    text-align: left;
    padding: 10px 14px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #8a929e;
    background: #fafbfc;
    border-bottom: 1px solid #e8ecef;
    white-space: nowrap;
}

.data-table td {
    padding: 12px 14px;
    border-bottom: 1px solid #f4f5f7;
    vertical-align: middle;
}

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

.data-table tr:hover td { background: #fafbff; }

/* ── Status Badges ─────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.badge--draft     { background: #f0f2f4; color: #8a929e; }
.badge--active    { background: #d1fae5; color: #065f46; }
.badge--submitted { background: #dbeafe; color: #1e40af; }
.badge--confirmed { background: #d1fae5; color: #065f46; }
.badge--exported  { background: #ede9fe; color: #5b21b6; }
.badge--cancelled { background: #fee2e2; color: #991b1b; }
.badge--approved  { background: #d1fae5; color: #065f46; }
.badge--received  { background: #fef9c3; color: #854d0e; }
.badge--incomplete{ background: #fee2e2; color: #991b1b; }
.badge--outlet    { background: #fde8d8; color: #9a3412; }
.badge--co        { background: #ede9fe; color: #5b21b6; }

/* ── Forms ─────────────────────────────────────────────── */
.form-group { margin-bottom: 18px; }

.form-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: #5a6474;
    margin-bottom: 6px;
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid #d0d7de;
    border-radius: 7px;
    font-size: 0.875rem;
    color: var(--color-accent);
    background: #fff;
    transition: border-color 0.15s, box-shadow 0.15s;
    outline: none;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-primary) 15%, transparent);
}

.form-textarea { resize: vertical; min-height: 80px; }

/* ── Alerts ────────────────────────────────────────────── */
.alert {
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 0.875rem;
    margin-bottom: 20px;
    border-left: 4px solid;
}

.alert--success {
    background: #d1fae5;
    color: #065f46;
    border-color: #10b981;
}

.alert--error {
    background: #fee2e2;
    color: #991b1b;
    border-color: #ef4444;
}

.alert--warning {
    background: #fef9c3;
    color: #854d0e;
    border-color: #f59e0b;
}

.alert--info {
    background: #dbeafe;
    color: #1e40af;
    border-color: #3b82f6;
}

/* ── Auth Layout ───────────────────────────────────────── */
.auth-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--color-bg);
    flex-direction: column;
    gap: 24px;
}

.auth-shell {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    width: 100%;
    padding: 32px 16px;
}

.auth-card {
    background: #fff;
    border-radius: 14px;
    border: 1px solid #e8ecef;
    padding: 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.06);
}

.auth-logo {
    text-align: center;
    margin-bottom: 28px;
}

.auth-logo img {
    max-height: 60px;
    max-width: 200px;
    object-fit: contain;
}

.auth-title {
    font-size: 1.5rem;
    font-weight: 800;
    text-align: center;
    color: var(--color-accent);
    margin-bottom: 4px;
}

.auth-subtitle {
    text-align: center;
    color: #8a929e;
    font-size: 0.875rem;
    margin-bottom: 28px;
}

.auth-form { display: flex; flex-direction: column; }

.auth-footer {
    text-align: center;
    margin-top: 20px;
    font-size: 0.8rem;
    color: #8a929e;
}

.auth-platform-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    opacity: 0.5;
    font-size: 0.75rem;
    color: #8a929e;
}

.auth-platform-brand img {
    height: 22px;
    object-fit: contain;
    filter: grayscale(1);
}

/* ── Dashboard ─────────────────────────────────────────── */
.dashboard-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 20px;
    margin-top: 8px;
}

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: #8a929e;
    font-size: 0.875rem;
}

/* ── Responsive ────────────────────────────────────────── */
@media (max-width: 900px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar   { display: none; }
    .page-body { padding: 20px 16px; }
    .topbar    { padding: 16px; }
    .dashboard-grid { grid-template-columns: 1fr; }
}

/* ── Budget bar ─────────────────────────────────────────────────── */
.budget-bar {
    height: 8px;
    background: #e9ecef;
    border-radius: 4px;
    overflow: hidden;
}
.budget-bar__fill {
    height: 100%;
    background: var(--color-primary);
    border-radius: 4px;
    transition: width 0.3s ease, background 0.3s ease;
}
.budget-bar__fill--warn { background: #f59e0b; }
.budget-bar__fill--over { background: #ef4444; }

/* ── Article photo thumbnails ───────────────────────────────────── */
.article-photo {
    width: 60px; height: 60px;
    background: #f8fafc;
    border-radius: 8px;
    border: 1px solid #e8ecef;
    flex-shrink: 0;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}
.article-photo img { width: 100%; height: 100%; object-fit: cover; }

/* ── Order matrix inputs ────────────────────────────────────────── */
.qty-input:focus { border-color: var(--color-primary); background: #fff8f0; outline: none; }
.qty-input:not([value=""]):not([value="0"]) { background: #f0faf8; border-color: #a0d4cc; font-weight: 700; }

/* ── Carry-over badge ───────────────────────────────────────────── */
.badge--co { background: #e0f2fe; color: #0369a1; }
.badge--received { background: #f3f4f6; color: #6b7280; }
.badge--incomplete { background: #fef3c7; color: #92400e; }
.badge--approved { background: #d1fae5; color: #065f46; }
.badge--active { background: #d1fae5; color: #065f46; }
.badge--draft { background: #f3f4f6; color: #6b7280; }
.badge--submitted { background: #dbeafe; color: #1e40af; }
.badge--confirmed { background: #ede9fe; color: #5b21b6; }
.badge--exported { background: #d1fae5; color: #065f46; }
.badge--cancelled { background: #fee2e2; color: #991b1b; }


/* ── Orders table action column ─────────────────────────────────── */
.data-table td:last-child { white-space: nowrap; }
.btn--sm { white-space: nowrap; }
