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

:root {
    --primary: #2563eb;
    --primary-light: #eff6ff;
    --success: #16a34a;
    --success-light: #f0fdf4;
    --warning: #d97706;
    --warning-light: #fffbeb;
    --danger: #dc2626;
    --danger-light: #fef2f2;
    --bg: #f5f7fa;
    --card-bg: #fff;
    --border: #e5e7eb;
    --text: #1f2937;
    --text-secondary: #6b7280;
    --text-muted: #9ca3af;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(0,0,0,.08);
}

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

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

/* Layout */
.layout { display: flex; min-height: 100vh; }

.sidebar {
    width: 220px;
    background: #1e293b;
    color: #e2e8f0;
    padding: 20px 0;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    overflow-y: auto;
    z-index: 100;
}

.sidebar-logo {
    padding: 0 20px 20px;
    border-bottom: 1px solid #334155;
    margin-bottom: 12px;
}

.sidebar-logo h2 { font-size: 18px; color: #fff; }
.sidebar-logo p { font-size: 12px; color: #94a3b8; margin-top: 2px; }

.sidebar-nav { list-style: none; }
.sidebar-nav li { padding: 0 12px; }
.sidebar-nav li a {
    display: block;
    padding: 10px 12px;
    border-radius: 6px;
    color: #cbd5e1;
    font-size: 14px;
    transition: all .15s;
}
.sidebar-nav li a:hover,
.sidebar-nav li a.active {
    background: #334155;
    color: #fff;
    text-decoration: none;
}

.sidebar-section {
    font-size: 11px;
    text-transform: uppercase;
    color: #64748b;
    padding: 16px 24px 6px;
    letter-spacing: 1px;
}

.main {
    margin-left: 220px;
    flex: 1;
    padding: 24px 32px;
    min-height: 100vh;
}

/* Header */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.page-header h1 { font-size: 22px; font-weight: 600; }

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
    color: var(--text-secondary);
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all .15s;
    white-space: nowrap;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: #1d4ed8; }

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #15803d; }

.btn-warning { background: var(--warning); color: #fff; }
.btn-warning:hover { background: #b45309; }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }

.btn-outline { background: #fff; border-color: var(--border); color: var(--text); }
.btn-outline:hover { background: #f9fafb; }

.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-lg { padding: 10px 24px; font-size: 16px; }

/* Cards */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 20px;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.card-title { font-size: 16px; font-weight: 600; }

/* Tables */
.table-wrap { overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

table th {
    text-align: left;
    padding: 10px 12px;
    border-bottom: 2px solid var(--border);
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 13px;
    white-space: nowrap;
}

table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

table tr:hover td { background: #fafbfc; }

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

.form-label {
    display: block;
    margin-bottom: 6px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
}

.form-input, .form-select, .form-textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    transition: border-color .15s;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}

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

.form-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.form-inline { display: flex; gap: 12px; align-items: end; flex-wrap: wrap; }

/* Badges */
.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}

.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(--primary-light); color: var(--primary); }
.badge-muted { background: #f3f4f6; color: var(--text-secondary); }

/* Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
}

.stat-label { font-size: 13px; color: var(--text-secondary); margin-bottom: 4px; }
.stat-value { font-size: 28px; font-weight: 700; color: var(--text); }
.stat-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* Modal */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal-overlay.open { display: flex; }

.modal {
    background: #fff;
    border-radius: var(--radius);
    padding: 24px;
    width: 90%;
    max-width: 560px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,.15);
}
.modal-actions {
    display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px;
    position: sticky; bottom: 0; background: #fff; padding-top: 12px;
    border-top: 1px solid var(--border); z-index: 5;
}

.modal-title { font-size: 18px; font-weight: 600; margin-bottom: 20px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }

.modal-close-x {
    position: sticky; top: 0; float: right;
    margin-right: -8px; margin-top: -8px;
    width: 28px; height: 28px; border-radius: 50%;
    background: #f3f4f6; color: #6b7280; border: none;
    cursor: pointer; font-size: 16px; line-height: 28px; text-align: center;
    transition: all .15s; z-index: 10;
}
.modal-close-x:hover { background: #e5e7eb; color: #1f2937; }

/* Loading spinner */
.spinner-overlay {
    display: none; position: fixed; inset: 0; z-index: 3000;
    background: rgba(255,255,255,.6);
    align-items: center; justify-content: center;
}
.spinner-overlay.show { display: flex; }
.spinner {
    width: 40px; height: 40px;
    border: 4px solid #e5e7eb;
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Toast */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    border-radius: 8px;
    color: #fff;
    font-size: 14px;
    animation: slideIn .2s ease;
    max-width: 360px;
}

.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-info { background: var(--primary); }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* Upload component */
.upload-area {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 16px;
    text-align: center;
    transition: border-color .2s;
}
.upload-area:hover { border-color: var(--primary); }
.upload-preview { margin-bottom: 12px; }
.upload-preview img, .upload-preview video { max-width: 200px; max-height: 200px; border-radius: 6px; object-fit: cover; }
.upload-preview-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.upload-preview-item { position: relative; width: 120px; height: 120px; }
.upload-preview-item img { width: 120px; height: 120px; object-fit: cover; border-radius: 6px; }
.upload-preview-item .remove-btn { position: absolute; top: -6px; right: -6px; width: 20px; height: 20px; border-radius: 50%; background: var(--danger); color: #fff; border: none; cursor: pointer; font-size: 12px; line-height: 20px; text-align: center; }
.upload-placeholder { padding: 24px 0; color: var(--text-muted); }
.upload-icon { font-size: 36px; margin-bottom: 8px; }
.upload-text { font-size: 13px; }
.upload-btn, .upload-remove-btn { margin: 4px; }

/* Rich text (Quill) */
.ql-toolbar.ql-snow { border-radius: 6px 6px 0 0; border-color: var(--border); background: #fafbfc; }
.ql-container.ql-snow { border-radius: 0 0 6px 6px; border-color: var(--border); min-height: 200px; font-size: 14px; }
.ql-editor { min-height: 200px; }

/* Search bar */
.search-bar { display: flex; gap: 8px; margin-bottom: 16px; }
.search-bar .search-input { max-width: 320px; }

/* ── H5 Mobile Layout (Technician) ── */
.h5-layout { min-height: 100vh; background: var(--bg); padding-bottom: 70px; }
.h5-header {
    position: sticky; top: 0; z-index: 50;
    background: var(--primary); color: #fff;
    padding: 12px 16px; display: flex;
    align-items: center; justify-content: space-between;
    box-shadow: 0 2px 8px rgba(0,0,0,.1);
}
.h5-header h1 { font-size: 17px; font-weight: 600; }
.h5-header .user-badge { font-size: 13px; opacity: .85; }
.h5-main { padding: 12px 12px 24px; }

/* Bottom tab bar */
.h5-tabs {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
    background: #fff; border-top: 1px solid var(--border);
    display: flex; padding-bottom: env(safe-area-inset-bottom);
}
.h5-tab {
    flex: 1; text-align: center; padding: 8px 4px 6px;
    font-size: 11px; color: var(--text-muted); text-decoration: none;
    transition: color .15s;
}
.h5-tab .tab-icon { font-size: 20px; display: block; margin-bottom: 2px; }
.h5-tab.active { color: var(--primary); font-weight: 600; }
.h5-tab:hover { text-decoration: none; color: var(--primary); }

/* Mobile cards (instead of tables) */
.h5-card {
    background: #fff; border-radius: 10px; padding: 14px;
    margin-bottom: 10px; box-shadow: var(--shadow);
}
.h5-card .card-row { display: flex; justify-content: space-between; align-items: center; padding: 4px 0; }
.h5-card .card-label { font-size: 12px; color: var(--text-muted); }
.h5-card .card-value { font-size: 14px; color: var(--text); font-weight: 500; }
.h5-card .card-title { font-size: 15px; font-weight: 600; margin-bottom: 6px; }
.h5-card .card-thumb { width: 56px; height: 56px; border-radius: 8px; object-fit: cover; flex-shrink: 0; }
.h5-card .card-actions { display: flex; gap: 8px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); }

/* Mobile modal */
.h5-modal .modal { max-width: 95vw; max-height: 90vh; padding: 16px; }

/* Tablet & desktop: show tables, hide cards */
@media (min-width: 769px) {
    .h5-cards { display: none; }
    .h5-table { display: block; }
}
@media (max-width: 768px) {
    .h5-table { display: none; }
    .h5-cards { display: block; }
    .h5-header h1 { font-size: 16px; }
}

/* Login page */
.login-page {
    display: flex;
    min-height: 100vh;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
}

.login-card {
    background: #fff;
    border-radius: 12px;
    padding: 40px;
    width: 400px;
    box-shadow: 0 20px 60px rgba(0,0,0,.2);
}

.login-card h1 { font-size: 24px; text-align: center; margin-bottom: 8px; }
.login-card .subtitle { text-align: center; color: var(--text-secondary); font-size: 14px; margin-bottom: 28px; }

.login-tabs {
    display: flex;
    margin-bottom: 24px;
    border-bottom: 2px solid var(--border);
}

.login-tab {
    flex: 1;
    text-align: center;
    padding: 10px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all .15s;
}

.login-tab:hover { color: var(--text); }
.login-tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* Empty state */
.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-muted);
}

.empty-state-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state-text { font-size: 15px; }

/* Responsive */
@media (max-width: 768px) {
    .sidebar { width: 60px; }
    .sidebar-logo h2, .sidebar-logo p, .sidebar-nav li a span, .sidebar-section { display: none; }
    .main { margin-left: 60px; padding: 16px; }
    .page-header { flex-direction: column; align-items: flex-start; gap: 8px; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .form-inline { flex-direction: column; }
}
