/* ============================================================
   Telasis Asset Manager — Stylesheet v2.5
   Brand: Telasis blue #0066B3, teal #00A5B5, orange #E87722
   Mobile-first responsive design
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --primary:       #0066B3;
    --primary-dark:  #004E8C;
    --primary-light: #e8f2fc;
    --secondary:     #00A5B5;
    --secondary-light:#e0f7f9;
    --accent:        #E87722;
    --success:       #059669;
    --success-light: #ecfdf5;
    --warning:       #d97706;
    --warning-light: #fffbeb;
    --danger:        #dc2626;
    --danger-light:  #fef2f2;
    --info:          #0891b2;
    --info-light:    #ecfeff;
    --bg:            #f1f5f9;
    --bg-card:       #ffffff;
    --text:          #1e293b;
    --text-muted:    #64748b;
    --border:        #e2e8f0;
    --sidebar-bg:    #0a1628;
    --sidebar-text:  #94a3b8;
    --sidebar-active:#0066B3;
    --sidebar-width: 260px;
    --radius:        8px;
    --radius-lg:     12px;
    --shadow:        0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
    --shadow-lg:     0 10px 15px rgba(0,0,0,.1), 0 4px 6px rgba(0,0,0,.05);
    --transition:    all .2s ease;
}

html { font-size: 15px; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif; background: var(--bg); color: var(--text); line-height: 1.6; -webkit-text-size-adjust: 100%; }
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }
img { max-width: 100%; height: auto; }

/* ── Layout ────────────────────────────────────────────────── */
.app-wrapper { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-width); background: var(--sidebar-bg);
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 1000;
    display: flex; flex-direction: column;
    transition: transform .3s ease;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
.sidebar-header {
    padding: 1.25rem 1rem; border-bottom: 1px solid rgba(255,255,255,.08);
    display: flex; align-items: center; gap: .75rem;
}
.sidebar-header img { height: 36px; width: auto; }
.sidebar-header .app-title { color: #fff; font-size: 1rem; font-weight: 600; }

.nav-section { padding: .5rem 0; }
.nav-section-label { padding: .5rem 1.25rem; font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: rgba(255,255,255,.35); font-weight: 600; }

.nav-links { list-style: none; flex: 1; padding: .5rem 0; overflow-y: auto; }
.nav-links li a {
    display: flex; align-items: center; gap: .75rem;
    padding: .6rem 1.25rem; color: var(--sidebar-text);
    font-size: .9rem; transition: var(--transition); border-left: 3px solid transparent;
    min-height: 44px; /* Touch target */
}
.nav-links li a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-links li.active a { background: rgba(0,102,179,.2); color: #fff; border-left-color: var(--primary); font-weight: 500; }
.nav-links li a svg { width: 20px; height: 20px; flex-shrink: 0; opacity: .7; }
.nav-links li.active a svg { opacity: 1; }
.nav-divider { height: 1px; background: rgba(255,255,255,.08); margin: .5rem 0; }

.sidebar-footer { padding: 1rem; border-top: 1px solid rgba(255,255,255,.08); }
.user-info { display: flex; justify-content: space-between; align-items: center; margin-bottom: .5rem; }
.user-name { color: #fff; font-size: .85rem; font-weight: 500; }
.user-role { font-size: .65rem; }

/* Sidebar overlay for mobile */
.sidebar-overlay {
    display: none;
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,.5); z-index: 999;
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
}
.app-wrapper.sidebar-open .sidebar-overlay { display: block; }

/* Main */
.main-content { flex: 1; margin-left: var(--sidebar-width); display: flex; flex-direction: column; min-height: 100vh; }
.top-bar {
    background: var(--bg-card); padding: .85rem 1.5rem;
    display: flex; align-items: center; gap: 1rem;
    position: sticky; top: 0; z-index: 50;
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
    flex-wrap: wrap;
}
.sidebar-toggle {
    background: none; border: none; cursor: pointer; color: var(--text);
    display: none; padding: 8px; min-width: 44px; min-height: 44px;
    align-items: center; justify-content: center;
}
.page-title { font-size: 1.2rem; font-weight: 600; white-space: nowrap; }
.breadcrumb { display: flex; align-items: center; gap: .4rem; font-size: .82rem; color: var(--text-muted); margin-left: 1rem; flex-wrap: wrap; }
.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--primary); }
.breadcrumb .sep { opacity: .4; }

.content-area { padding: 1.5rem; flex: 1; }
.main-footer { padding: .75rem 1.5rem; font-size: .8rem; color: var(--text-muted); border-top: 1px solid var(--border); text-align: center; }

/* ── Stats ─────────────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card {
    background: var(--bg-card); border-radius: var(--radius-lg); padding: 1.25rem;
    display: flex; align-items: center; gap: 1rem;
    box-shadow: var(--shadow); transition: var(--transition);
}
.stat-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); }
.stat-icon {
    width: 52px; height: 52px; border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.stat-icon svg { width: 24px; height: 24px; }
.stat-icon.blue { background: var(--primary-light); color: var(--primary); }
.stat-icon.green { background: var(--success-light); color: var(--success); }
.stat-icon.amber { background: var(--warning-light); color: var(--warning); }
.stat-icon.red { background: var(--danger-light); color: var(--danger); }
.stat-icon.cyan { background: var(--info-light); color: var(--info); }
.stat-icon.teal { background: var(--secondary-light); color: var(--secondary); }
.stat-value { font-size: 1.5rem; font-weight: 700; line-height: 1.2; }
.stat-label { font-size: .82rem; color: var(--text-muted); }

/* ── Cards ─────────────────────────────────────────────────── */
.card { background: var(--bg-card); border-radius: var(--radius-lg); box-shadow: var(--shadow); margin-bottom: 1.5rem; overflow: hidden; }
.card-header { padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: .5rem; }
.card-header h3 { font-size: 1rem; font-weight: 600; }
.card-body { padding: 1.25rem; }

/* ── Tables ────────────────────────────────────────────────── */
.table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -1.25rem; padding: 0 1.25rem; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
thead { background: var(--bg); }
th { padding: .7rem .75rem; text-align: left; font-weight: 600; color: var(--text-muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
td { padding: .65rem .75rem; border-top: 1px solid var(--border); vertical-align: middle; }
tbody tr:hover { background: #f8fafc; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }

/* Sortable table headers */
th.sortable { cursor: pointer; user-select: none; position: relative; padding-right: 1.5rem; }
th.sortable:hover { color: var(--primary); background: var(--primary-light); }
th.sortable .sort-icon { position: absolute; right: .4rem; top: 50%; transform: translateY(-50%); font-size: .7rem; opacity: .3; }
th.sortable.sort-asc .sort-icon, th.sortable.sort-desc .sort-icon { opacity: 1; color: var(--primary); }

/* ── Badges ────────────────────────────────────────────────── */
.badge {
    display: inline-flex; align-items: center; padding: .2rem .65rem;
    border-radius: 20px; font-size: .72rem; font-weight: 600;
    text-transform: uppercase; letter-spacing: .02em; white-space: nowrap;
}
.badge-primary { background: var(--primary-light); color: var(--primary); }
.badge-success { background: var(--success-light); color: var(--success); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-info { background: var(--info-light); color: var(--info); }
.badge-secondary { background: #f1f5f9; color: #475569; }
.badge-teal { background: var(--secondary-light); color: var(--secondary); }

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; gap: .4rem;
    padding: .55rem 1.1rem; font-size: .88rem; font-weight: 500;
    border: none; border-radius: var(--radius); cursor: pointer;
    transition: var(--transition); text-decoration: none; white-space: nowrap;
    min-height: 44px; /* Touch target */
    justify-content: center;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 2px 4px rgba(0,0,0,.12); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #047857; color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { background: var(--bg); border-color: var(--primary); color: var(--primary); }
.btn-sm { padding: .35rem .7rem; font-size: .82rem; min-height: 36px; }
.btn-lg { padding: .7rem 1.4rem; font-size: 1rem; }
.btn svg { width: 16px; height: 16px; }
.btn-group { display: flex; gap: .4rem; flex-wrap: wrap; }

/* ── Forms ──────────────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; margin-bottom: .3rem; font-size: .85rem; font-weight: 500; color: var(--text); }
.form-control {
    width: 100%; padding: .55rem .85rem; font-size: .9rem;
    border: 1px solid var(--border); border-radius: var(--radius);
    background: #fff; color: var(--text); transition: var(--transition);
    font-family: inherit; min-height: 44px; /* Touch target */
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(0,102,179,.12); }
select.form-control { appearance: auto; }
textarea.form-control { min-height: 80px; resize: vertical; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; }
.form-inline { display: flex; gap: .75rem; flex-wrap: wrap; align-items: end; }
.required { color: var(--danger); }

/* File input styled */
.form-control-file {
    width: 100%; padding: .5rem; font-size: .9rem;
    border: 2px dashed var(--border); border-radius: var(--radius);
    background: var(--bg); cursor: pointer; min-height: 44px;
}
.form-control-file:hover { border-color: var(--primary); }

/* ── Search Bar ────────────────────────────────────────────── */
.search-bar { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; align-items: center; }
.search-bar .form-control { flex: 1; min-width: 180px; }

/* ── Alerts ────────────────────────────────────────────────── */
.alert { padding: .85rem 1.15rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: .9rem; border-left: 4px solid; }
.alert-success { background: var(--success-light); color: #065f46; border-color: var(--success); }
.alert-danger { background: var(--danger-light); color: #991b1b; border-color: var(--danger); }
.alert-warning { background: var(--warning-light); color: #92400e; border-color: var(--warning); }
.alert-info { background: var(--info-light); color: #155e75; border-color: var(--info); }

/* ── Pagination ────────────────────────────────────────────── */
.pagination { display: flex; gap: .3rem; justify-content: center; margin-top: 1.25rem; flex-wrap: wrap; }
.pagination a, .pagination span {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 36px; height: 36px; padding: 0 .5rem;
    border: 1px solid var(--border); border-radius: var(--radius);
    font-size: .85rem; color: var(--text); transition: var(--transition);
}
.pagination a:hover { background: var(--primary-light); border-color: var(--primary); color: var(--primary); }
.pagination .active { background: var(--primary); color: #fff; border-color: var(--primary); font-weight: 600; }

/* ── Detail Grid ───────────────────────────────────────────── */
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: .5rem 1.5rem; }
.detail-item { padding: .6rem 0; }
.detail-label { font-size: .75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; margin-bottom: .15rem; }
.detail-value { font-size: .95rem; font-weight: 500; word-break: break-word; }

/* ── Empty State ───────────────────────────────────────────── */
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--text-muted); }
.empty-state svg { margin-bottom: .75rem; opacity: .4; }

/* ── Login Page ────────────────────────────────────────────── */
.login-wrapper {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #0a1628 0%, #0066B3 50%, #00A5B5 100%);
    padding: 1rem;
}
.login-card {
    background: var(--bg-card); border-radius: var(--radius-lg); padding: 2.5rem;
    width: 100%; max-width: 420px; box-shadow: var(--shadow-lg);
}
.login-card .logo-area { text-align: center; margin-bottom: 1.5rem; }
.login-card .logo-area img { height: 48px; margin-bottom: .5rem; }
.login-card h1 { text-align: center; font-size: 1.3rem; font-weight: 700; margin-bottom: .3rem; }
.login-card .subtitle { text-align: center; color: var(--text-muted); font-size: .9rem; margin-bottom: 1.5rem; }
.login-card .btn { width: 100%; justify-content: center; padding: .7rem; font-size: 1rem; }

/* ── Checkbox bulk actions ─────────────────────────────────── */
.bulk-actions-bar {
    display: none; padding: .75rem 1.25rem; background: var(--primary-light);
    border-bottom: 1px solid var(--border); align-items: center; gap: 1rem;
    flex-wrap: wrap;
}
.bulk-actions-bar.visible { display: flex; }
.bulk-actions-bar .selected-count { font-weight: 600; font-size: .9rem; color: var(--primary); }
.bulk-checkbox { width: 18px; height: 18px; cursor: pointer; accent-color: var(--primary); min-width: 18px; }

/* ── Modal ─────────────────────────────────────────────────── */
.modal-overlay {
    display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,.5); z-index: 2000; align-items: center; justify-content: center;
    padding: 1rem;
}
.modal-overlay.active { display: flex; }
.modal {
    background: var(--bg-card); border-radius: var(--radius-lg); padding: 0;
    width: 100%; max-width: 500px; box-shadow: var(--shadow-lg); max-height: 90vh; overflow-y: auto;
}
.modal-header { padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-header h3 { font-size: 1.1rem; font-weight: 600; }
.modal-close { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--text-muted); padding: 4px 8px; min-width: 44px; min-height: 44px; display: flex; align-items: center; justify-content: center; }
.modal-body { padding: 1.25rem; }
.modal-footer { padding: 1rem 1.25rem; border-top: 1px solid var(--border); display: flex; gap: .5rem; justify-content: flex-end; flex-wrap: wrap; }

/* ── PDF Viewer ────────────────────────────────────────────── */
.pdf-viewer-container { width: 100%; background: #525659; border-radius: var(--radius); overflow: hidden; position: relative; }
.pdf-viewer-container iframe, .pdf-viewer-container embed { width: 100%; min-height: 600px; border: none; display: block; }
.pdf-toolbar { display: flex; gap: .5rem; padding: .75rem; background: var(--sidebar-bg); align-items: center; flex-wrap: wrap; }
.pdf-toolbar .btn { min-height: 36px; }

/* ── CSV Import preview ────────────────────────────────────── */
.csv-preview-table { font-size: .82rem; }
.csv-preview-table td, .csv-preview-table th { padding: .4rem .5rem; }
.csv-row-error { background: var(--danger-light); }
.csv-row-ok { background: var(--success-light); }
.csv-row-skip { background: var(--warning-light); }

/* ── Utility Classes ───────────────────────────────────────── */
.flex-between { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: .5rem; }
.flex-center { display: flex; align-items: center; gap: .5rem; }
.mt-1 { margin-top: .5rem; } .mt-2 { margin-top: 1rem; } .mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: .5rem; } .mb-2 { margin-bottom: 1rem; } .mb-3 { margin-bottom: 1.5rem; }
.gap-1 { gap: .5rem; } .gap-2 { gap: 1rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }
.w-full { width: 100%; }
.hidden { display: none; }

/* ── Progress Bar (for charts) ─────────────────────────────── */
.progress-bar-container { display: flex; align-items: center; gap: .5rem; margin-bottom: .5rem; }
.progress-bar-label { font-size: .82rem; min-width: 120px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.progress-bar { flex: 1; height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; }
.progress-bar-fill { height: 100%; border-radius: 4px; transition: width .5s ease; }
.progress-bar-value { font-size: .82rem; font-weight: 600; min-width: 30px; text-align: right; }

/* ── Tabs ──────────────────────────────────────────────────── */
.tabs { display: flex; gap: 0; border-bottom: 2px solid var(--border); margin-bottom: 1rem; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tab { padding: .6rem 1.25rem; font-size: .88rem; font-weight: 500; color: var(--text-muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px; transition: var(--transition); text-decoration: none; white-space: nowrap; min-height: 44px; display: flex; align-items: center; }
.tab:hover { color: var(--primary); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ── Responsive: Tablet ────────────────────────────────────── */
@media (max-width: 1024px) {
    .stats-grid { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
    .form-row { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
}

/* ── Responsive: Mobile ────────────────────────────────────── */
@media (max-width: 768px) {
    :root { --sidebar-width: 280px; }

    .sidebar { transform: translateX(-100%); }
    .app-wrapper.sidebar-open .sidebar { transform: translateX(0); }
    .sidebar-toggle { display: flex; }
    .main-content { margin-left: 0; }

    .top-bar { padding: .75rem 1rem; gap: .5rem; }
    .page-title { font-size: 1.05rem; }
    .breadcrumb { margin-left: 0; width: 100%; order: 3; font-size: .78rem; }

    .content-area { padding: 1rem; }

    .stats-grid { grid-template-columns: 1fr 1fr; gap: .75rem; }
    .stat-card { padding: 1rem; gap: .75rem; }
    .stat-icon { width: 44px; height: 44px; }
    .stat-value { font-size: 1.25rem; }

    .grid-2, .grid-3 { grid-template-columns: 1fr; }
    .detail-grid { grid-template-columns: 1fr; }
    .form-row { grid-template-columns: 1fr; }

    .card-body { padding: 1rem; }
    .card-header { padding: .85rem 1rem; }

    /* Search bar stack on mobile */
    .search-bar { flex-direction: column; align-items: stretch; }
    .search-bar .form-control { min-width: 100%; flex: none; }
    .search-bar select.form-control { flex: none !important; width: 100% !important; }
    .search-bar .btn { width: 100%; }

    /* Responsive tables: horizontal scroll with shadow hint */
    .table-responsive { margin: 0 -1rem; padding: 0 1rem; position: relative; }
    .table-responsive::after {
        content: ''; position: absolute; top: 0; right: 0; bottom: 0; width: 24px;
        background: linear-gradient(to right, transparent, rgba(255,255,255,.8));
        pointer-events: none;
    }
    table { min-width: 700px; }
    th, td { padding: .5rem .6rem; }

    /* Buttons full width on mobile in some contexts */
    .flex-between .btn-group { width: 100%; justify-content: flex-end; }

    /* Modal */
    .modal { max-width: 100%; margin: 0; border-radius: var(--radius) var(--radius) 0 0; }

    /* PDF viewer */
    .pdf-viewer-container iframe, .pdf-viewer-container embed { min-height: 400px; }

    /* Login */
    .login-card { padding: 1.75rem; }
    .login-card h1 { font-size: 1.15rem; }
}

/* ── Responsive: Small Phone ───────────────────────────────── */
@media (max-width: 480px) {
    html { font-size: 14px; }

    .stats-grid { grid-template-columns: 1fr; gap: .5rem; }
    .stat-card { padding: .85rem; }

    .content-area { padding: .75rem; }
    .card-body { padding: .85rem; }

    table { font-size: .8rem; min-width: 600px; }
    th, td { padding: .45rem .5rem; }

    .btn { padding: .5rem .85rem; font-size: .82rem; }
    .btn-lg { padding: .6rem 1rem; font-size: .92rem; }
    .btn-group { flex-direction: column; width: 100%; }
    .btn-group .btn { width: 100%; }

    .page-title { font-size: .95rem; }
    .badge { font-size: .65rem; padding: .15rem .5rem; }

    .detail-grid { gap: 0; }
    .detail-item { padding: .5rem 0; }

    .form-row { gap: .75rem; }
    .form-group { margin-bottom: .75rem; }

    .pagination a, .pagination span { min-width: 32px; height: 32px; font-size: .8rem; }

    /* PDF viewer smaller on tiny phones */
    .pdf-viewer-container iframe, .pdf-viewer-container embed { min-height: 300px; }
}

/* ── Print styles ──────────────────────────────────────────── */
@media print {
    .sidebar, .sidebar-overlay, .sidebar-toggle, .top-bar, .main-footer,
    .search-bar, .pagination, .btn-group, .bulk-actions-bar, .modal-overlay { display: none !important; }
    .main-content { margin-left: 0 !important; }
    .content-area { padding: 0 !important; }
    .card { box-shadow: none; border: 1px solid #ddd; break-inside: avoid; }
    body { background: #fff; }
    a { color: #000; }
}
