/* EvoStock — Base Styles */

@import url("grid-WRqDMxO.css");
@import url("safety-stock-HFk-Fiz.css");
@import url("modal-Ra4Gc0k.css");
@import url("sku-details-ZVksHQ8.css");

:root {
    --color-primary: #2563eb;
    --color-primary-dark: #1d4ed8;
    --color-danger: #dc2626;
    --color-warning: #f59e0b;
    --color-success: #16a34a;
    --color-bg: #f8fafc;
    --color-surface: #ffffff;
    --color-text: #1e293b;
    --color-text-muted: #64748b;
    --color-border: #e2e8f0;
    --color-safety-breach: #fef2f2;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,.1);
    --shadow-lg: 0 4px 6px rgba(0,0,0,.1);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header / Nav */
.app-header {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}
.app-nav {
    display: flex;
    align-items: center;
    gap: 2rem;
    max-width: 1440px;
    margin: 0 auto;
    padding: .75rem 1.5rem;
}
.app-logo {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--color-primary);
    text-decoration: none;
}
.app-nav__links {
    display: flex;
    list-style: none;
    gap: 1rem;
}
.app-nav__links a {
    text-decoration: none;
    color: var(--color-text-muted);
    padding: .25rem .5rem;
    border-radius: var(--radius);
    transition: color .15s, background .15s;
}
.app-nav__links a:hover,
.app-nav__links a.active {
    color: var(--color-primary);
    background: #eff6ff;
}
.app-nav__user {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: .75rem;
    font-size: .875rem;
    color: var(--color-text-muted);
}
.app-nav__user a { color: var(--color-danger); text-decoration: none; }

/* Main */
.app-main {
    flex: 1;
    max-width: 1440px;
    margin: 0 auto;
    padding: 1.5rem;
    width: 100%;
}

body.dashboard-layout {
    height: 100vh;
    overflow: hidden;
}

body.dashboard-layout .app-main--dashboard {
    max-width: none;
    width: 100%;
    display: flex;
    flex: 1 1 auto;
    min-height: 0;
    min-width: 0;
    overflow: hidden;
}

body.dashboard-layout .app-main--dashboard .dashboard {
    display: grid;
    grid-template-rows: auto auto auto 1fr;
    grid-template-columns: minmax(0, 1fr);
    height: 100%;
    width: 100%;
    min-height: 0;
    min-width: 0;
}

body.dashboard-layout .app-main--dashboard .dashboard > turbo-frame#stock-grid {
    display: flex;
    flex-direction: column;
    width: 100%;
    min-height: 0;
    min-width: 0;
    overflow: hidden;
}

body.dashboard-layout .app-main--dashboard .dashboard .dashboard-grid-shell {
    position: relative;
    display: flex;
    flex: 1 1 auto;
    width: 100%;
    min-height: clamp(24rem, 62vh, 48rem);
    min-width: 0;
    overflow: hidden;
}

body.dashboard-layout .app-main--dashboard .dashboard .dashboard-grid-shell > turbo-frame#stock-grid {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    width: 100%;
    min-height: 0;
    min-width: 0;
    overflow: hidden;
}

body.dashboard-layout .app-main--dashboard .dashboard .dashboard-grid-shell[data-loading="true"] > turbo-frame#stock-grid {
    opacity: .4;
    filter: saturate(.85);
    pointer-events: none;
}

body.dashboard-layout .app-main--dashboard .dashboard .dashboard-grid-shell[data-initial-loading="true"] > turbo-frame#stock-grid {
    visibility: hidden;
}

body.dashboard-layout .app-main--dashboard .dashboard .dashboard-grid-loading {
    position: absolute;
    inset: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(248, 250, 252, .72);
    backdrop-filter: blur(2px);
}

body.dashboard-layout .app-main--dashboard .dashboard .dashboard-grid-loading__content {
    display: inline-flex;
    align-items: center;
    gap: .75rem;
    padding: .85rem 1.15rem;
    border: 1px solid rgba(148, 163, 184, .28);
    border-radius: 999px;
    background: rgba(255, 255, 255, .92);
    box-shadow: 0 20px 45px rgba(15, 23, 42, .08);
    color: var(--color-text);
    font-size: .95rem;
    font-weight: 600;
}

.snapshot-selector__select {
    min-width: 22rem;
    max-width: min(32rem, 42vw);
}

@media (max-width: 991.98px) {
    .snapshot-selector__select {
        min-width: 0;
        max-width: 100%;
    }
}

body.dashboard-layout .app-main--dashboard .dashboard .stock-grid {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    width: 100%;
    min-height: 0;
    min-width: 0;
    overflow: hidden;
}

body.dashboard-layout .app-main--dashboard .dashboard .stock-grid .table-responsive {
    flex: 1 1 auto;
    width: 100%;
    min-height: 0;
    min-width: 0;
    overflow: auto;
    max-height: none;
}

/* Footer */
.app-footer {
    text-align: center;
    padding: 1rem;
    font-size: .75rem;
    color: var(--color-text-muted);
    border-top: 1px solid var(--color-border);
}

/* Flash Messages */
.flash {
    padding: .75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: .875rem;
}
.flash--success { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
.flash--danger, .flash--error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.flash--warning { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.flash--info { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }
.flash button {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.25rem;
    color: inherit;
    opacity: .6;
}
.flash button:hover { opacity: 1; }

/* Legacy Buttons */
.btn-legacy {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    padding: .5rem 1rem;
    border-radius: var(--radius);
    font-size: .875rem;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text);
    text-decoration: none;
    transition: all .15s;
}
.btn-legacy:hover { box-shadow: var(--shadow); }
.btn--primary { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }
.btn--primary:hover { background: var(--color-primary-dark); }
.btn--danger { background: var(--color-danger); color: #fff; border-color: var(--color-danger); }
.btn--sm { padding: .25rem .75rem; font-size: .8125rem; }
.btn--full { width: 100%; justify-content: center; }

/* Forms */
.form-group {
    margin-bottom: 1rem;
}
.form-group label {
    display: block;
    font-size: .875rem;
    font-weight: 500;
    margin-bottom: .25rem;
    color: var(--color-text);
}
.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: .5rem .75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: .875rem;
    transition: border-color .15s;
}
.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}

/* Login Page */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 70px);
    flex-grow: 1;
}
.login-card {
    background: var(--color-surface);
    padding: 2rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 400px;
    text-align: center;
}
.login-card h1 { font-size: 1.75rem; margin-bottom: .25rem; }
.login-subtitle { color: var(--color-text-muted); margin-bottom: 1.5rem; font-size: .875rem; }
.login-form { text-align: left; }
.login-actions {
    display: grid;
    gap: .75rem;
}
.login-divider {
    color: var(--color-text-muted);
    font-size: .75rem;
    font-weight: 600;
    letter-spacing: .04em;
    text-transform: uppercase;
}
.login-dev-actions {
    display: grid;
    gap: .5rem;
}

/* Cards */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.card__header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.card__body { padding: 1.5rem; }

/* Tables */
.table-responsive { overflow-x: auto; }
table {
    width: 100%;
    border-collapse: collapse;
    font-size: .875rem;
}
th, td {
    padding: .5rem .75rem;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
}
th {
    font-weight: 600;
    background: #f8fafc;
    position: sticky;
    top: 0;
    z-index: 1;
}

/* Stock Grid */
.stock-grid {
    overflow-x: auto;
}
.stock-grid table { min-width: 800px; }
.stock-grid th.date-col,
.stock-grid td.date-col {
    min-width: 80px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}
.stock-grid td.cell--below-safety {
    color: var(--color-danger);
    font-weight: 700;
}

.stock-grid td.cell--stockout {
    background: var(--color-safety-breach);
}

.stock-grid td.cell--stockout-overstock {
    background: repeating-linear-gradient(
        -45deg,
        #fecaca,
        #fecaca 4px,
        #bfdbfe 4px,
        #bfdbfe 8px
    );
}

/* Toolbar */
.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: .75rem;
    align-items: center;
    margin-bottom: 1rem;
}
.toolbar__search {
    flex: 1;
    min-width: 200px;
}
.toolbar__search input {
    width: 100%;
    padding: .5rem .75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: .875rem;
}
.toolbar__filters {
    display: flex;
    gap: .5rem;
    align-items: center;
}

/* Pagination */
.pagination {
    display: flex;
    gap: .25rem;
    justify-content: center;
    align-items: center;
    margin-top: 1rem;
    flex-wrap: wrap;
}
.pagination a,
.pagination span {
    padding: .375rem .75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: .8125rem;
    text-decoration: none;
    color: var(--color-text);
}
.pagination a:hover { background: #f1f5f9; }
.pagination .current {
    background: var(--color-primary);
    color: #fff;
    border-color: var(--color-primary);
}

/* Badge */
.badge {
    display: inline-flex;
    align-items: center;
    gap: .25rem;
    padding: .125rem .5rem;
    border-radius: 9999px;
    font-size: .75rem;
    font-weight: 500;
}
.badge--ok { background: #dcfce7; color: #166534; }
.badge--warning { background: #fef9c3; color: #854d0e; }
.badge--error { background: #fee2e2; color: #991b1b; }
.badge--stale { background: #fef9c3; color: #854d0e; }
.badge--syncing { background: #dbeafe; color: #1e40af; animation: pulse-badge 1.5s ease-in-out infinite; }

@keyframes pulse-badge {
    0%, 100% { opacity: 1; }
    50% { opacity: .6; }
}

/* Freshness bar */
.freshness-bar {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .5rem 1rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: .8125rem;
    margin-bottom: 1rem;
}

/* Settings page */
.settings-grid {
    display: grid;
    gap: 1.5rem;
}

/* Spinner */
.spinner {
    display: inline-block;
    width: 1em;
    height: 1em;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin .6s linear infinite;
    vertical-align: middle;
}
.spinner--sm {
    width: .8em;
    height: .8em;
    border-width: 1.5px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Sync progress */
.sync-progress {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    color: var(--color-primary);
    font-weight: 500;
    font-size: .875rem;
    padding: .5rem 0;
}

.sync-progress-bar {
    max-width: 20rem;
}

.sync-progress-bar .progress-bar {
    min-width: 3rem;
}

/* Syncing button state */
.btn--syncing {
    opacity: .7;
    cursor: not-allowed;
    pointer-events: none;
}
.btn--syncing .spinner {
    margin-right: .25rem;
}

/* Fullscreen mode */
body.dashboard-fullscreen .app-header,
body.dashboard-fullscreen .app-main--dashboard .dashboard > h1,
body.dashboard-fullscreen .app-main--dashboard .freshness-bar,
body.dashboard-fullscreen .app-footer {
    display: none !important;
}

body.dashboard-fullscreen .app-main--dashboard {
    padding-top: .5rem;
}

body.dashboard-fullscreen .app-main--dashboard .dashboard {
    grid-template-rows: auto auto 1fr;
}

.btn-fullscreen {
    background: none;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: .35rem .6rem;
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
    color: var(--color-text-muted);
    transition: color .15s, border-color .15s;
}
.btn-fullscreen:hover {
    color: var(--color-primary);
    border-color: var(--color-primary);
}

/* Responsive */
@media (max-width: 768px) {
    .app-nav { flex-wrap: wrap; gap: .5rem; }
    .app-nav__links { order: 3; width: 100%; }
    .toolbar { flex-direction: column; }
    .toolbar__search { min-width: 100%; }
}
