/* ═══════════════════════════════════════════════════
   ERP Mobile App Shell
   ═══════════════════════════════════════════════════ */

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

html {
    height: 100%;
    -webkit-text-size-adjust: 100%;
}

.app-body {
    margin: 0;
    height: 100%;
    height: 100dvh;
    overflow: hidden;
    background: #f1f5f9;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
}

.app-shell {
    display: flex;
    height: 100%;
    height: 100dvh;
    overflow: hidden;
}

.app-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    height: 100%;
    overflow: hidden;
}

.app-header {
    flex-shrink: 0;
    background: #1e40af;
    color: #fff;
    padding-top: env(safe-area-inset-top, 0);
    z-index: 20;
}

.app-header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.875rem 1rem;
    min-height: 3.25rem;
}

.app-title {
    margin: 0;
    font-size: 1.125rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.app-user {
    font-size: 0.75rem;
    opacity: 0.85;
    background: rgba(255,255,255,0.15);
    padding: 0.25rem 0.625rem;
    border-radius: 9999px;
}

.app-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: 1rem;
    padding-bottom: calc(7.5rem + env(safe-area-inset-bottom, 0));
}

@media (min-width: 1024px) {
    .app-content {
        padding: 1.5rem;
        padding-bottom: 1.5rem;
    }
}

/* ── Desktop sidebar ── */
.desktop-sidebar {
    width: 16rem;
    flex-shrink: 0;
    flex-direction: column;
    background: #1e3a8a;
    color: #fff;
}

.desktop-sidebar-brand {
    padding: 1rem;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}
.desktop-sidebar-brand h1 { margin: 0; font-size: 1.125rem; font-weight: 700; }
.desktop-sidebar-brand p { margin: 0.25rem 0 0; font-size: 0.75rem; color: #93c5fd; }

.desktop-sidebar-nav {
    flex: 1;
    padding: 0.75rem;
    overflow-y: auto;
}

.desktop-sidebar-footer {
    padding: 0.75rem;
    border-top: 1px solid rgba(255,255,255,0.1);
}

.sidebar-section {
    padding: 0.75rem 0.75rem 0.25rem;
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #60a5fa;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 0.75rem;
    border-radius: 0.625rem;
    font-size: 0.875rem;
    color: #bfdbfe;
    text-decoration: none;
    transition: background 0.15s;
}
.sidebar-link:hover { background: rgba(255,255,255,0.1); color: #fff; }
.sidebar-link.active { background: rgba(255,255,255,0.15); color: #fff; font-weight: 500; }
.sidebar-link-danger { color: #fca5a5 !important; }
.sidebar-link-danger:hover { color: #fecaca !important; }

.sidebar-badge {
    margin-left: auto;
    background: #ef4444;
    color: #fff;
    font-size: 0.6875rem;
    font-style: normal;
    padding: 0.125rem 0.5rem;
    border-radius: 9999px;
    font-weight: 600;
}

/* ── Bottom navigation (mobile) ── */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 30;
    display: flex;
    background: #fff;
    border-top: 1px solid #e2e8f0;
    box-shadow: 0 -4px 24px rgba(15, 23, 42, 0.08);
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.2rem;
    padding: 0.5rem 0.25rem 0.625rem;
    font-size: 0.625rem;
    font-weight: 500;
    color: #64748b;
    text-decoration: none;
    border: none;
    background: none;
    cursor: pointer;
    position: relative;
    -webkit-tap-highlight-color: transparent;
}
.bottom-nav-item svg { width: 1.375rem; height: 1.375rem; }
.bottom-nav-item.active { color: #1d4ed8; }
.bottom-nav-item.active svg { stroke-width: 2.25; }

.bottom-nav-badge {
    position: absolute;
    top: 0.2rem;
    right: calc(50% - 1.25rem);
    background: #ef4444;
    color: #fff;
    font-size: 0.5625rem;
    font-style: normal;
    font-weight: 700;
    min-width: 1rem;
    height: 1rem;
    line-height: 1rem;
    text-align: center;
    border-radius: 9999px;
    padding: 0 0.2rem;
}

/* ── Settings bottom sheet ── */
.settings-sheet {
    position: fixed;
    inset: 0;
    z-index: 40;
    background: rgba(15, 23, 42, 0.45);
    display: flex;
    align-items: flex-end;
}
.settings-sheet.hidden { display: none; }

.settings-sheet-panel {
    width: 100%;
    background: #fff;
    border-radius: 1.25rem 1.25rem 0 0;
    padding: 0.75rem 1rem calc(1.25rem + env(safe-area-inset-bottom, 0));
    animation: slide-up 0.25s ease-out;
}

.settings-sheet-handle {
    width: 2.5rem;
    height: 0.25rem;
    background: #cbd5e1;
    border-radius: 9999px;
    margin: 0 auto 1rem;
}

.settings-sheet-title {
    margin: 0 0 0.75rem;
    font-size: 1rem;
    font-weight: 600;
    color: #0f172a;
}

.settings-sheet-links { display: flex; flex-direction: column; gap: 0.25rem; }

.settings-sheet-link {
    display: flex;
    align-items: center;
    gap: 0.875rem;
    padding: 0.875rem 0.75rem;
    border-radius: 0.75rem;
    font-size: 0.9375rem;
    font-weight: 500;
    color: #1e293b;
    text-decoration: none;
}
.settings-sheet-link svg { width: 1.25rem; height: 1.25rem; color: #64748b; }
.settings-sheet-link:active { background: #f1f5f9; }

@keyframes slide-up {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
}

/* ── Page toolbar ── */
.page-toolbar {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1rem;
}
@media (min-width: 640px) {
    .page-toolbar { flex-direction: row; align-items: center; }
}

.page-search {
    display: flex;
    gap: 0.5rem;
    flex: 1;
}

.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    padding: 0.625rem 1rem;
    background: #1d4ed8;
    color: #fff;
    font-size: 0.875rem;
    font-weight: 600;
    border: none;
    border-radius: 0.75rem;
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
}
.btn-primary:active { background: #1e40af; }

.btn-secondary {
    padding: 0.625rem 1rem;
    background: #f1f5f9;
    color: #475569;
    font-size: 0.875rem;
    font-weight: 500;
    border: none;
    border-radius: 0.75rem;
    cursor: pointer;
}
.btn-danger {
    padding: 0.625rem 1rem;
    background: #dc2626;
    color: #fff;
    font-size: 0.875rem;
    font-weight: 600;
    border: none;
    border-radius: 0.75rem;
    cursor: pointer;
}

.btn-sm {
    padding: 0.4375rem 0.75rem;
    font-size: 0.8125rem;
    border-radius: 0.5rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.btn-sm-green { background: #16a34a; color: #fff; }
.btn-sm-red   { background: #dc2626; color: #fff; }
.btn-sm-blue  { background: #dbeafe; color: #1d4ed8; }
.btn-sm-amber { background: #fef3c7; color: #b45309; }
.btn-sm-gray  { background: #f1f5f9; color: #475569; }

/* ── Stat cards ── */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    margin-bottom: 1rem;
}
@media (min-width: 1024px) {
    .stat-grid { grid-template-columns: repeat(4, 1fr); gap: 1rem; margin-bottom: 1.5rem; }
}

.stat-card {
    background: #fff;
    border-radius: 1rem;
    padding: 1rem;
    box-shadow: 0 1px 3px rgba(15,23,42,0.06);
}
.stat-card p { margin: 0; font-size: 0.75rem; color: #64748b; }
.stat-card strong { display: block; font-size: 1.75rem; font-weight: 700; margin-top: 0.25rem; line-height: 1.1; }
.stat-amber strong { color: #d97706; }
.stat-blue strong  { color: #2563eb; }
.stat-green strong { color: #16a34a; }
.stat-red strong   { color: #dc2626; }

/* ── App cards ── */
.app-card {
    background: #fff;
    border-radius: 1rem;
    box-shadow: 0 1px 3px rgba(15,23,42,0.06);
    overflow: hidden;
}

.app-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.875rem 1rem;
    border-bottom: 1px solid #f1f5f9;
}
.app-card-header h3 { margin: 0; font-size: 0.9375rem; font-weight: 600; color: #0f172a; }
.app-card-header a { font-size: 0.8125rem; color: #2563eb; text-decoration: none; font-weight: 500; }

/* ── Request cards ── */
.request-cards { display: flex; flex-direction: column; gap: 0.75rem; }

.request-card {
    background: #fff;
    border-radius: 1rem;
    padding: 1rem;
    box-shadow: 0 1px 3px rgba(15,23,42,0.06);
}

.request-card-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.request-card-id {
    font-size: 0.9375rem;
    font-weight: 700;
    color: #0f172a;
    margin: 0;
}

.request-card-centre {
    font-size: 0.8125rem;
    color: #64748b;
    margin: 0.2rem 0 0;
}

.request-card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    font-size: 0.75rem;
    color: #64748b;
    margin-bottom: 0.875rem;
}
.request-card-meta span { display: flex; align-items: center; gap: 0.25rem; }

.request-card-actions {
    display: flex;
    gap: 0.5rem;
    padding-top: 0.75rem;
    border-top: 1px solid #f1f5f9;
}
.request-card-actions form { flex: 1; }
.request-card-actions .btn-sm,
.request-card-actions a.btn-sm { flex: 1; width: 100%; }

/* ── Item cards (request detail) ── */
.item-cards { display: flex; flex-direction: column; gap: 0.625rem; padding: 0.75rem; }

.item-card {
    background: #f8fafc;
    border-radius: 0.75rem;
    padding: 0.875rem;
    border: 1px solid #e2e8f0;
}

.item-card-name { font-weight: 600; font-size: 0.9375rem; color: #0f172a; margin: 0 0 0.5rem; }
.item-card-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.375rem 0.75rem;
    font-size: 0.75rem;
}
.item-card-grid dt { color: #64748b; margin: 0; }
.item-card-grid dd { color: #0f172a; font-weight: 500; margin: 0; text-align: right; }

.item-card-total {
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px dashed #cbd5e1;
    display: flex;
    justify-content: space-between;
    font-size: 0.8125rem;
    font-weight: 600;
}

.grand-total-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: #eff6ff;
    border-radius: 0 0 1rem 1rem;
    font-weight: 700;
    font-size: 0.9375rem;
    color: #1e3a8a;
}

/* ── Badges ── */
.badge {
    display: inline-block;
    font-size: 0.6875rem;
    font-weight: 600;
    padding: 0.2rem 0.5rem;
    border-radius: 9999px;
    white-space: nowrap;
}
.badge-amber  { background: #fef3c7; color: #b45309; }
.badge-green  { background: #dcfce7; color: #15803d; }
.badge-red    { background: #fee2e2; color: #b91c1c; }
.badge-blue   { background: #dbeafe; color: #1d4ed8; }
.badge-purple { background: #f3e8ff; color: #7e22ce; }
.badge-gray   { background: #f1f5f9; color: #475569; }

/* ── Responsive data table ── */
.data-table-wrap {
    background: #fff;
    border-radius: 1rem;
    box-shadow: 0 1px 3px rgba(15,23,42,0.06);
    overflow: hidden;
}

.data-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.data-table thead { background: #f8fafc; }
.data-table th {
    padding: 0.75rem 1rem;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.data-table td { padding: 0.875rem 1rem; color: #334155; border-top: 1px solid #f1f5f9; }
.data-table .td-actions { text-align: right; white-space: nowrap; }
.data-table .row-name { font-weight: 600; color: #0f172a; }

.data-table-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: flex-end;
}
.data-table-actions a,
.data-table-actions button {
    font-size: 0.8125rem;
    font-weight: 600;
    border: none;
    background: none;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 0.375rem;
    text-decoration: none;
}
.link-edit   { color: #2563eb; }
.link-toggle { color: #d97706; }
.link-delete { color: #dc2626; }

/* Mobile: card-style rows */
@media (max-width: 767px) {
    .data-table thead { display: none; }
    .data-table tbody tr {
        display: block;
        margin: 0.625rem;
        padding: 0.875rem;
        background: #f8fafc;
        border-radius: 0.75rem;
        border: 1px solid #e2e8f0;
    }
    .data-table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.3rem 0;
        border: none;
        gap: 1rem;
    }
    .data-table td::before {
        content: attr(data-label);
        font-size: 0.75rem;
        font-weight: 500;
        color: #64748b;
        flex-shrink: 0;
    }
    .data-table td.td-actions {
        display: block;
        padding-top: 0.625rem;
        margin-top: 0.375rem;
        border-top: 1px solid #e2e8f0;
    }
    .data-table td.td-actions::before { display: none; }
    .data-table-actions { justify-content: flex-start; }
}

/* Desktop: horizontal scroll fallback for wide tables */
@media (min-width: 768px) {
    .data-table-scroll { overflow-x: auto; }
}

/* ── Filter panel ── */
.filter-panel {
    background: #fff;
    border-radius: 1rem;
    padding: 1rem;
    margin-bottom: 1rem;
    box-shadow: 0 1px 3px rgba(15,23,42,0.06);
}
.filter-panel summary {
    font-size: 0.875rem;
    font-weight: 600;
    color: #1e293b;
    cursor: pointer;
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.filter-panel summary::-webkit-details-marker { display: none; }
.filter-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75rem;
    margin-top: 0.875rem;
}
@media (min-width: 640px) {
    .filter-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 1024px) {
    .filter-grid { grid-template-columns: repeat(4, 1fr) auto; align-items: end; }
}
.filter-label { display: block; font-size: 0.75rem; font-weight: 500; color: #64748b; margin-bottom: 0.25rem; }

/* ── Empty state ── */
.empty-state {
    text-align: center;
    padding: 2.5rem 1rem;
    color: #94a3b8;
    font-size: 0.875rem;
}

/* ── Pagination ── */
.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-top: 1px solid #f1f5f9;
    font-size: 0.8125rem;
    color: #64748b;
}
.pagination-pages { display: flex; gap: 0.25rem; flex-wrap: wrap; }
.pagination-pages a {
    padding: 0.375rem 0.625rem;
    border-radius: 0.5rem;
    text-decoration: none;
    color: #475569;
    font-weight: 500;
}
.pagination-pages a.active { background: #1d4ed8; color: #fff; }

/* ── Detail header ── */
.detail-header {
    background: #fff;
    border-radius: 1rem;
    padding: 1rem;
    margin-bottom: 0.75rem;
    box-shadow: 0 1px 3px rgba(15,23,42,0.06);
}
.detail-header h3 { margin: 0; font-size: 1.0625rem; font-weight: 700; color: #0f172a; }
.detail-header p { margin: 0.35rem 0 0; font-size: 0.8125rem; color: #64748b; }
.detail-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.875rem;
    margin-bottom: 0.5rem;
    padding-top: 0.875rem;
    border-top: 1px solid #f1f5f9;
}
.detail-actions form { flex: 1; }
.detail-actions button { width: 100%; }

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    margin-top: 1rem;
    margin-bottom: 1.5rem;
    font-size: 0.875rem;
    color: #2563eb;
    text-decoration: none;
    font-weight: 500;
}

.page-bottom-spacer {
    height: 1.5rem;
    flex-shrink: 0;
}

/* ── Form pages ── */
.form-page-card {
    background: #fff;
    border-radius: 1rem;
    padding: 1.25rem;
    box-shadow: 0 1px 3px rgba(15,23,42,0.06);
    max-width: 42rem;
}
.form-page-card label { display: block; font-size: 0.875rem; font-weight: 500; color: #374151; margin-bottom: 0.25rem; }
.form-page-card .field { margin-bottom: 1rem; }
.form-actions { display: flex; flex-wrap: wrap; gap: 0.625rem; padding-top: 0.5rem; }

/* ── Loading / toast / confirm ── */
.loading-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 50;
    background: rgba(15,23,42,0.35);
    align-items: center;
    justify-content: center;
}
.loading-overlay.is-visible { display: flex; }
.loading-box {
    background: #fff;
    border-radius: 1rem;
    padding: 1.25rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.875rem;
    color: #334155;
    box-shadow: 0 20px 40px rgba(15,23,42,0.15);
}

.toast-container {
    position: fixed;
    top: calc(0.75rem + env(safe-area-inset-top, 0));
    left: 0.75rem;
    right: 0.75rem;
    z-index: 50;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
}
.toast-container > div {
    pointer-events: auto;
    padding: 0.75rem 1rem;
    border-radius: 0.75rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: #fff;
    box-shadow: 0 4px 16px rgba(15,23,42,0.15);
}

.confirm-dialog {
    position: fixed;
    inset: 0;
    z-index: 50;
    background: rgba(15,23,42,0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.confirm-dialog.hidden { display: none; }
.confirm-dialog-box {
    background: #fff;
    border-radius: 1rem;
    padding: 1.25rem;
    width: 100%;
    max-width: 20rem;
    box-shadow: 0 20px 40px rgba(15,23,42,0.2);
}
.confirm-dialog-box h3 { margin: 0 0 0.5rem; font-size: 1rem; font-weight: 600; }
.confirm-dialog-box p { margin: 0 0 1.25rem; font-size: 0.875rem; color: #64748b; }
.confirm-dialog-actions { display: flex; gap: 0.5rem; justify-content: flex-end; }

.install-banner {
    position: fixed;
    bottom: calc(4.5rem + env(safe-area-inset-bottom, 0));
    left: 0.75rem;
    right: 0.75rem;
    z-index: 35;
    background: #1e3a8a;
    color: #fff;
    border-radius: 1rem;
    padding: 0.875rem;
    box-shadow: 0 8px 24px rgba(15,23,42,0.2);
}
@media (min-width: 1024px) {
    .install-banner { bottom: 1rem; left: auto; right: 1rem; max-width: 24rem; }
}
.install-banner.hidden { display: none; }
.install-banner-inner { display: flex; align-items: center; gap: 0.75rem; }
.install-btn {
    padding: 0.4375rem 0.875rem;
    background: #fff;
    color: #1e3a8a;
    border: none;
    border-radius: 0.5rem;
    font-size: 0.8125rem;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
}

@keyframes slide-in {
    from { transform: translateY(-0.5rem); opacity: 0; }
    to   { transform: translateY(0); opacity: 1; }
}
.animate-slide-in { animation: slide-in 0.25s ease-out; }

/* ── Auth pages (unchanged essentials) ── */
.bg-auth-page {
    background: linear-gradient(135deg, #1e3a8a 0%, #1e40af 50%, #1d4ed8 100%);
    min-height: 100vh;
}

input[type="text"], input[type="password"], input[type="email"],
input[type="number"], input[type="date"], input[type="search"],
input[type="tel"], input[type="url"], select, textarea {
    color: #111827 !important;
    background-color: #ffffff !important;
    -webkit-text-fill-color: #111827;
    color-scheme: light;
}
input::placeholder, textarea::placeholder { color: #9ca3af !important; opacity: 1; }
input[readonly], textarea[readonly] {
    color: #374151 !important;
    background-color: #f9fafb !important;
    -webkit-text-fill-color: #374151;
}
input:-webkit-autofill, input:-webkit-autofill:hover, input:-webkit-autofill:focus, textarea:-webkit-autofill {
    -webkit-text-fill-color: #111827 !important;
    -webkit-box-shadow: 0 0 0 1000px #ffffff inset !important;
    box-shadow: 0 0 0 1000px #ffffff inset !important;
}
select option { color: #111827; background-color: #ffffff; }

.auth-card {
    background-color: #ffffff;
    color: #111827;
    border-radius: 1rem;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
}
.auth-card label { color: #374151; }
.auth-card button[type="submit"] { background-color: #1d4ed8; color: #ffffff; }
.btn-cta { background-color: #ffffff; color: #1e40af; }

/* Hide desktop table on mobile for request pages - cards used instead */
.desktop-only-table { display: none; }
@media (min-width: 1024px) {
    .desktop-only-table { display: block; }
    .mobile-only-cards { display: none !important; }
}
