/* =========================================================
   Tiles Management System — Core SaaS Design System
   ========================================================= */

:root {
    --tms-primary: #4f46e5;
    --tms-primary-dark: #4338ca;
    --tms-bg: #f4f5f9;
    --tms-surface: #ffffff;
    --tms-border: #e5e7eb;
    --tms-text: #1f2430;
    --tms-text-muted: #6b7280;
    --tms-sidebar-bg: #14162b;
    --tms-sidebar-text: #a3a7c2;
    --tms-sidebar-text-active: #ffffff;
    --tms-radius: 10px;
    --tms-radius-lg: 14px;
    --tms-shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
    --sidebar-width: 260px;
    --sidebar-width-collapsed: 76px;
    --header-height: 64px;
}

* { box-sizing: border-box; }

/* Consistent keyboard-focus ring app-wide, instead of each browser's own
   default outline (which is inconsistent, and invisible on the dark sidebar). */
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible,
textarea:focus-visible, .icon-btn:focus-visible, .nav-link:focus-visible {
    outline: 2px solid var(--tms-primary);
    outline-offset: 2px;
    border-radius: 4px;
}

body {
    background: var(--tms-bg);
    color: var(--tms-text);
    font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, Arial, sans-serif;
    font-size: 14px;
}

a { text-decoration: none; }

/* ---------- App shell ---------- */
.app-shell {
    display: flex;
    min-height: 100vh;
}

.app-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    margin-left: var(--sidebar-width);
    transition: margin-left .2s ease;
}

body.sidebar-collapsed .app-main {
    margin-left: var(--sidebar-width-collapsed);
}

/* ---------- Sidebar ---------- */
.sidebar {
    width: var(--sidebar-width);
    background: var(--tms-sidebar-bg);
    color: var(--tms-sidebar-text);
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    z-index: 1030;
    transition: width .2s ease, transform .2s ease;
    overflow-y: auto;
}

body.sidebar-collapsed .sidebar {
    width: var(--sidebar-width-collapsed);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: 1.1rem 1.25rem;
    color: #fff;
    font-size: 1.05rem;
    font-weight: 600;
    border-bottom: 1px solid rgba(255,255,255,.08);
    white-space: nowrap;
}

.sidebar-brand i { flex-shrink: 0; width: 22px; height: 22px; color: var(--tms-primary); }

body.sidebar-collapsed .brand-text { display: none; }

.sidebar-nav {
    padding: .75rem .75rem 1.5rem;
    display: flex;
    flex-direction: column;
    gap: .15rem;
}

.nav-section-label {
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: #62678c;
    padding: 1rem .6rem .3rem;
    white-space: nowrap;
}

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

.nav-link {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .6rem .75rem;
    border-radius: var(--tms-radius);
    color: var(--tms-sidebar-text);
    font-size: .875rem;
    font-weight: 500;
    white-space: nowrap;
}

.nav-link i { width: 18px; height: 18px; flex-shrink: 0; }

.nav-link:hover { background: rgba(255,255,255,.06); color: #fff; }

.nav-link.active {
    background: var(--tms-primary);
    color: #fff;
}

.nav-link.disabled {
    opacity: .45;
    cursor: not-allowed;
    pointer-events: none;
}

body.sidebar-collapsed .nav-link span { display: none; }

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 17, 35, .45);
    z-index: 1020;
}

body.sidebar-open .sidebar-overlay { display: block; }

/* ---------- Header ---------- */
.app-header {
    height: var(--header-height);
    background: var(--tms-surface);
    border-bottom: 1px solid var(--tms-border);
    box-shadow: 0 1px 2px rgba(16, 24, 40, .04);
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: 0 1.25rem;
    position: sticky;
    top: 0;
    z-index: 1010;
}

.header-spacer { flex: 1; }

.header-actions { display: flex; align-items: center; gap: .5rem; }

.icon-btn {
    width: 38px;
    height: 38px;
    border-radius: 999px;
    border: 1px solid var(--tms-border);
    background: var(--tms-surface);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--tms-text-muted);
}

.icon-btn:hover { background: var(--tms-bg); color: var(--tms-text); }
.icon-btn i { width: 18px; height: 18px; }

.user-chip {
    display: flex;
    align-items: center;
    gap: .5rem;
    border: 1px solid var(--tms-border);
    background: var(--tms-surface);
    border-radius: 999px;
    padding: .3rem .7rem .3rem .3rem;
}

.user-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--tms-primary);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.user-avatar i { width: 16px; height: 16px; }
.chevron { width: 14px; height: 14px; color: var(--tms-text-muted); }

/* ---------- Breadcrumb ---------- */
.app-breadcrumb {
    padding: .75rem 1.25rem;
    border-bottom: 1px solid var(--tms-border);
    background: var(--tms-surface);
}

.breadcrumb-item a { color: var(--tms-text-muted); }
.breadcrumb-item.active { color: var(--tms-text); font-weight: 500; }

/* ---------- Content ---------- */
.app-content { padding: 1.5rem; }

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}

.page-title { font-size: 1.4rem; font-weight: 700; margin: 0; }
.page-subtitle { color: var(--tms-text-muted); margin: .2rem 0 0; }

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

.card-header {
    background: transparent;
    border-bottom: 1px solid var(--tms-border);
    padding: 1rem 1.25rem;
}

.card-title { font-size: 1rem; font-weight: 600; margin: 0; }
.card-body { padding: 1.25rem; }

.stat-card {
    background: var(--tms-surface);
    border: 1px solid var(--tms-border);
    border-radius: var(--tms-radius-lg);
    box-shadow: var(--tms-shadow);
    padding: 1rem;
    display: flex;
    align-items: center;
    gap: .85rem;
}

.stat-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--tms-radius);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.stat-icon i { width: 20px; height: 20px; }

.bg-primary-soft { background: #eef0ff; color: var(--tms-primary); }
.bg-success-soft { background: #e9fbf1; color: #17a057; }
.bg-warning-soft { background: #fff7e6; color: #b7791f; }
.bg-danger-soft { background: #fdecec; color: #d64545; }

.stat-value { font-size: 1.25rem; font-weight: 700; line-height: 1; }
.stat-label { color: var(--tms-text-muted); font-size: .8rem; margin-top: .2rem; }

.stock-summary-card { cursor: pointer; transition: box-shadow .15s ease, transform .15s ease; }
.stock-summary-card:hover { box-shadow: 0 4px 14px rgba(0,0,0,.08); transform: translateY(-1px); }

/* ---------- Buttons ---------- */
.btn-primary {
    background: var(--tms-primary);
    border-color: var(--tms-primary);
}

.btn-primary:hover, .btn-primary:focus {
    background: var(--tms-primary-dark);
    border-color: var(--tms-primary-dark);
}

.btn { border-radius: var(--tms-radius); font-weight: 500; }
.btn i { width: 16px; height: 16px; vertical-align: -3px; margin-right: .3rem; }

/* ---------- Forms ---------- */
.form-control, .form-select {
    border-radius: var(--tms-radius);
    border-color: var(--tms-border);
    padding: .55rem .75rem;
}

.form-control:focus, .form-select:focus {
    border-color: var(--tms-primary);
    box-shadow: 0 0 0 .2rem rgba(79, 70, 229, .15);
}

.form-label { font-weight: 500; font-size: .85rem; }

/* ---------- Tables ---------- */
.table {
    margin-bottom: 0;
}

.table thead th {
    background: #fafafa;
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--tms-text-muted);
    border-bottom: 1px solid var(--tms-border);
    font-weight: 600;
}

.table td, .table th { padding: .75rem 1rem; vertical-align: middle; }

/* ---------- Badges ---------- */
.badge { font-weight: 500; padding: .4em .65em; border-radius: 999px; }

.badge-soft-success { background: #e9fbf1; color: #17a057; }
.badge-soft-warning { background: #fff7e6; color: #b7791f; }
.badge-soft-danger { background: #fdecec; color: #d64545; }
.badge-soft-secondary { background: #f1f2f6; color: var(--tms-text-muted); }

/* ---------- Alerts ---------- */
.alert { border-radius: var(--tms-radius-lg); border: 1px solid transparent; }
.alert i { width: 18px; height: 18px; }

/* ---------- Empty state ---------- */
.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--tms-text-muted);
}

.empty-state-icon {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--tms-bg);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto .75rem;
}

.empty-state-icon i { width: 26px; height: 26px; color: var(--tms-text-muted); }
.empty-state h3 { font-size: 1rem; color: var(--tms-text); margin-bottom: .25rem; }
.empty-state p { margin: 0; font-size: .875rem; }

/* ---------- Loading state ---------- */
.loading-row {
    display: flex;
    align-items: center;
    gap: .6rem;
    color: var(--tms-text-muted);
    font-size: .875rem;
}

.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid var(--tms-border);
    border-top-color: var(--tms-primary);
    border-radius: 50%;
    display: inline-block;
    animation: tms-spin .7s linear infinite;
}

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

/* ---------- Modals ---------- */
.modal-content { border-radius: var(--tms-radius-lg); border: none; }
.modal-header { border-bottom: 1px solid var(--tms-border); }
.modal-footer { border-top: 1px solid var(--tms-border); }

/* ---------- Toasts ---------- */
.toast-container { z-index: 1080; }

.tms-toast {
    min-width: 260px;
    border-radius: var(--tms-radius);
    box-shadow: var(--tms-shadow);
    border: 1px solid var(--tms-border);
}

/* ---------- Auth pages ---------- */
.auth-body {
    background: var(--tms-sidebar-bg);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

.auth-wrapper { width: 100%; max-width: 420px; }

.auth-card {
    background: var(--tms-surface);
    border-radius: var(--tms-radius-lg);
    box-shadow: 0 12px 28px rgba(15, 17, 35, .18);
    padding: 2rem;
}

.auth-brand {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-weight: 700;
    color: var(--tms-primary);
    margin-bottom: 1.25rem;
}

.auth-title { font-size: 1.3rem; font-weight: 700; margin-bottom: .25rem; }
.auth-subtitle { color: var(--tms-text-muted); margin-bottom: 1.5rem; font-size: .9rem; }
.d-none-empty:empty { display: none !important; }

/* =========================================================
   Responsive
   ========================================================= */
@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(-100%);
    }

    body.sidebar-open .sidebar {
        transform: translateX(0);
    }

    .app-main {
        margin-left: 0 !important;
    }
}

@media (max-width: 575.98px) {
    .app-content { padding: 1rem; }
    .card-body { padding: 1rem; }
    .auth-card { padding: 1.5rem; }
}

/* =========================================================
   Reports + print-friendly layout
   ========================================================= */
.print-only { display: none; }

.report-totals td, .report-totals th {
    font-weight: 600;
    background: #fafafa;
    border-top: 2px solid var(--tms-border);
}

@media print {
    .sidebar, .sidebar-overlay, .app-header, .app-breadcrumb,
    .toast-container, .no-print { display: none !important; }

    .print-only { display: block !important; }

    body { background: #fff; font-size: 11px; }
    .app-main { margin-left: 0 !important; }
    .app-content { padding: 0 !important; }

    .card { border: none !important; box-shadow: none !important; }
    .card-header { display: none !important; }
    .table-responsive { overflow: visible !important; }
    .table thead th { background: #f0f0f0 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .badge { border: 1px solid #ccc; }
    tr { page-break-inside: avoid; }
    thead { display: table-header-group; }
    a { color: inherit !important; }
}

/* =========================================================
   Dashboard
   ========================================================= */
.stat-card-link { display: block; height: 100%; color: inherit; text-decoration: none; }
.stat-card-link .stat-card { height: 100%; transition: border-color .15s ease, box-shadow .15s ease; }
.stat-card-link:hover .stat-card { border-color: var(--tms-primary); }

.stat-card .stat-value { font-size: 1.15rem; }
.stat-card .stat-sub { color: var(--tms-text-muted); font-size: .75rem; margin-top: .15rem; }

/* Tiny dependency-free bar chart (7-day trend). */
.mini-bars { display: flex; align-items: stretch; gap: 8px; height: 120px; }
.mini-bar { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.mini-bar .bar-track { flex: 1; display: flex; align-items: flex-end; justify-content: center; }
.mini-bar .bar {
    width: 100%; max-width: 34px; min-height: 3px;
    background: var(--tms-primary); border-radius: 6px 6px 0 0;
}
.mini-bars.purchase .bar { background: #f59e0b; }
.mini-bar .bar.is-empty { background: var(--tms-border); }
.mini-bar .bar-label { font-size: .7rem; color: var(--tms-text-muted); text-align: center; margin-top: 4px; }
