/* ─── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --color-primary: #2563eb;
  --color-primary-dark: #1d4ed8;
  --color-danger: #dc2626;
  --color-success: #16a34a;
  --color-warning: #d97706;
  --color-bg: #f8fafc;
  --color-surface: #ffffff;
  --color-border: #e2e8f0;
  --color-text: #1e293b;
  --color-muted: #64748b;
  --color-nav-bg: #1e293b;
  --color-nav-text: #e2e8f0;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --radius: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
}

html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body { font-family: var(--font); color: var(--color-text); background: var(--color-bg); line-height: 1.5; min-height: 100vh; display: flex; flex-direction: column; }
a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; height: auto; }

/* ─── Layout ─────────────────────────────────────────────────────────────── */
.page-wrapper { display: flex; flex-direction: column; min-height: 100vh; }
.main-content { flex: 1; padding: 24px 16px; max-width: 1400px; margin: 0 auto; width: 100%; }
.container { max-width: 900px; margin: 0 auto; }

/* ─── Nav ─────────────────────────────────────────────────────────────────── */
.navbar { background: var(--color-nav-bg); color: var(--color-nav-text); display: flex; align-items: center; padding: 0 16px; height: 56px; gap: 24px; position: sticky; top: 0; z-index: 100; box-shadow: var(--shadow); }
.navbar-brand { font-weight: 700; font-size: 1.1rem; color: #fff; white-space: nowrap; }
.navbar-brand:hover { text-decoration: none; color: #fff; }
.navbar-nav { display: flex; align-items: center; gap: 4px; list-style: none; margin: 0; padding: 0; }
.navbar-nav a { color: var(--color-nav-text); padding: 8px 12px; border-radius: var(--radius); font-size: .9rem; transition: background .15s; }
.navbar-nav a:hover, .navbar-nav a.active { background: rgba(255,255,255,.1); text-decoration: none; }
.navbar-spacer { flex: 1; }
.navbar-user { font-size: .85rem; color: #94a3b8; display: flex; align-items: center; gap: 12px; white-space: nowrap; }
.navbar-user a { color: #94a3b8; font-size: .85rem; }
.navbar-user a:hover { color: #fff; }
.navbar-hamburger { display: none; background: none; border: none; color: var(--color-nav-text); cursor: pointer; padding: 8px; font-size: 1.4rem; }
.navbar-menu { display: flex; align-items: center; gap: 8px; flex: 1; }

@media (max-width: 768px) {
  .navbar-hamburger { display: block; }
  .navbar-menu { display: none; position: absolute; top: 56px; left: 0; right: 0; background: var(--color-nav-bg); flex-direction: column; align-items: flex-start; padding: 12px 16px; gap: 4px; box-shadow: var(--shadow-md); z-index: 99; }
  .navbar-menu.open { display: flex; }
  .navbar-nav { flex-direction: column; width: 100%; }
  .navbar-nav a { display: block; padding: 10px 12px; }
  .navbar-spacer { display: none; }
  .navbar-user { flex-direction: column; align-items: flex-start; width: 100%; border-top: 1px solid rgba(255,255,255,.1); padding-top: 8px; margin-top: 4px; }
}

/* ─── Footer ─────────────────────────────────────────────────────────────── */
.footer { background: var(--color-nav-bg); color: #64748b; text-align: center; padding: 16px; font-size: .8rem; margin-top: auto; }

/* ─── Cards & Panels ──────────────────────────────────────────────────────── */
.card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-header { padding: 16px 20px; border-bottom: 1px solid var(--color-border); display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; }
.card-header h2, .card-header h3 { margin: 0; font-size: 1rem; }
.card-body { padding: 20px; }

/* ─── Buttons ─────────────────────────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; border-radius: var(--radius); font-size: .875rem; font-weight: 500; cursor: pointer; border: none; text-decoration: none; transition: background .15s, box-shadow .15s; white-space: nowrap; line-height: 1.4; }
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-dark); color: #fff; }
.btn-danger { background: var(--color-danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; color: #fff; }
.btn-success { background: var(--color-success); color: #fff; }
.btn-success:hover { background: #15803d; color: #fff; }
.btn-secondary { background: #e2e8f0; color: var(--color-text); }
.btn-secondary:hover { background: #cbd5e1; color: var(--color-text); }
.btn-warning { background: var(--color-warning); color: #fff; }
.btn-warning:hover { background: #b45309; color: #fff; }
.btn-sm { padding: 4px 10px; font-size: .8rem; }
.btn-icon { padding: 6px; border-radius: var(--radius); background: transparent; border: 1px solid var(--color-border); cursor: pointer; font-size: .9rem; color: var(--color-muted); }
.btn-icon:hover { background: var(--color-border); }

/* ─── Forms ───────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: .875rem; font-weight: 500; margin-bottom: 4px; color: var(--color-text); }
.form-label .required { color: var(--color-danger); margin-left: 2px; }
.form-control { display: block; width: 100%; padding: 8px 12px; font-size: .9rem; border: 1px solid var(--color-border); border-radius: var(--radius); background: var(--color-surface); color: var(--color-text); transition: border-color .15s; min-height: 38px; font-family: var(--font); }
.form-control:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
textarea.form-control { min-height: 100px; resize: vertical; }
select.form-control { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8L1 3h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 28px; }
.form-control[multiple] { background-image: none; padding-right: 12px; min-height: 100px; }
.form-hint { font-size: .8rem; color: var(--color-muted); margin-top: 4px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
@media (max-width: 600px) { .form-row, .form-row-3 { grid-template-columns: 1fr; } }
.form-check { display: flex; align-items: center; gap: 8px; font-size: .9rem; margin-bottom: 8px; }
.form-check input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; }
.form-actions { display: flex; gap: 8px; align-items: center; margin-top: 20px; flex-wrap: wrap; }

/* ─── Tables ──────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.table th { background: #f1f5f9; text-align: left; padding: 10px 12px; font-weight: 600; color: var(--color-muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; border-bottom: 2px solid var(--color-border); white-space: nowrap; }
.table td { padding: 10px 12px; border-bottom: 1px solid var(--color-border); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table-hover tr:hover td { background: #f8fafc; }
.table-clickable tr { cursor: pointer; }
.table-clickable tr:hover td { background: #eff6ff; }
.table-empty { text-align: center; padding: 40px; color: var(--color-muted); }

/* ─── Badges ─────────────────────────────────────────────────────────────── */
.badge { display: inline-block; padding: 3px 8px; border-radius: 999px; font-size: .75rem; font-weight: 600; white-space: nowrap; }
.badge-low { background: #f1f5f9; color: #64748b; }
.badge-normal { background: #dbeafe; color: #1d4ed8; }
.badge-high { background: #fed7aa; color: #c2410c; }
.badge-urgent { background: #fee2e2; color: #dc2626; }
.badge-state-open { background: #dcfce7; color: #15803d; }
.badge-state-pending { background: #fef9c3; color: #a16207; }
.badge-state-resolved { background: #e0e7ff; color: #3730a3; }
.badge-state-closed { background: #f1f5f9; color: #64748b; }
.badge-js-progress { background: #dbeafe; color: #1d4ed8; }
.badge-js-customer { background: #fef3c7; color: #92400e; }
.badge-js-parts { background: #e0f2fe; color: #0369a1; }
.badge-js-third { background: #f3e8ff; color: #7c3aed; }
.badge-js-urgent { background: #fee2e2; color: #dc2626; }

/* ─── Flash messages ─────────────────────────────────────────────────────── */
.flash { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px; display: flex; align-items: center; gap: 8px; font-size: .9rem; }
.flash-success { background: #dcfce7; color: #15803d; border: 1px solid #bbf7d0; }
.flash-error { background: #fee2e2; color: #dc2626; border: 1px solid #fecaca; }
.flash-warning { background: #fef9c3; color: #a16207; border: 1px solid #fde68a; }
.flash-info { background: #dbeafe; color: #1d4ed8; border: 1px solid #bfdbfe; }
.flash-icon { font-weight: 700; }

/* ─── Page header ─────────────────────────────────────────────────────────── */
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-header h1 { font-size: 1.4rem; font-weight: 700; color: var(--color-text); }
.breadcrumb { font-size: .85rem; color: var(--color-muted); margin-bottom: 4px; }
.breadcrumb a { color: var(--color-muted); }
.breadcrumb a:hover { color: var(--color-primary); }

/* ─── Tabs ────────────────────────────────────────────────────────────────── */
.tabs { display: flex; gap: 0; border-bottom: 2px solid var(--color-border); margin-bottom: 20px; overflow-x: auto; }
.tab-btn { padding: 10px 20px; font-size: .9rem; font-weight: 500; border: none; background: none; cursor: pointer; color: var(--color-muted); border-bottom: 2px solid transparent; margin-bottom: -2px; white-space: nowrap; transition: color .15s; }
.tab-btn.active { color: var(--color-primary); border-bottom-color: var(--color-primary); }
.tab-btn:hover:not(.active) { color: var(--color-text); }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ─── Ticket timeline ─────────────────────────────────────────────────────── */
.timeline { display: flex; flex-direction: column; gap: 12px; }
.timeline-item { display: flex; gap: 12px; }
.timeline-avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--color-primary); color: #fff; display: flex; align-items: center; justify-content: center; font-size: .8rem; font-weight: 700; flex-shrink: 0; margin-top: 2px; }
.timeline-avatar.system { background: #94a3b8; font-size: .7rem; }
.timeline-body { flex: 1; min-width: 0; }
.timeline-meta { font-size: .8rem; color: var(--color-muted); margin-bottom: 4px; }
.timeline-content { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); padding: 10px 14px; font-size: .9rem; line-height: 1.5; }
.timeline-content.system { background: #f8fafc; border-color: #e2e8f0; font-size: .82rem; color: #64748b; font-style: italic; }

/* ─── Attachments ─────────────────────────────────────────────────────────── */
.attachment-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.attachment-item { border: 1px solid var(--color-border); border-radius: var(--radius); overflow: hidden; position: relative; }
.attachment-item img { width: 100%; height: 120px; object-fit: cover; display: block; }
.attachment-pdf { height: 120px; display: flex; align-items: center; justify-content: center; background: #fef2f2; font-size: 2rem; }
.attachment-meta { padding: 6px 8px; font-size: .75rem; color: var(--color-muted); }
.attachment-actions { display: flex; gap: 4px; padding: 0 8px 8px; }
.attachment-delete-form { position: absolute; top: 4px; right: 4px; }

/* ─── Stat cards ──────────────────────────────────────────────────────────── */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; margin-bottom: 24px; }
.stat-card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); padding: 16px 20px; box-shadow: var(--shadow); text-decoration: none; color: var(--color-text); display: block; transition: box-shadow .15s; }
.stat-card:hover { box-shadow: var(--shadow-md); text-decoration: none; }
.stat-card-num { font-size: 2rem; font-weight: 700; color: var(--color-primary); line-height: 1; margin-bottom: 4px; }
.stat-card-label { font-size: .8rem; color: var(--color-muted); }
.stat-card.urgent .stat-card-num { color: var(--color-danger); }
.stat-card.warning .stat-card-num { color: var(--color-warning); }

/* ─── Search & filters ───────────────────────────────────────────────────── */
.filter-bar { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.filter-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }
.filter-row .form-group { margin: 0; flex: 1; min-width: 150px; }
.filter-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.filter-tag { display: inline-flex; align-items: center; gap: 4px; background: #e0e7ff; color: #3730a3; border-radius: 999px; padding: 2px 8px; font-size: .78rem; font-weight: 500; }
.filter-tag button { background: none; border: none; cursor: pointer; color: #3730a3; font-size: .9rem; line-height: 1; padding: 0 0 0 2px; }

/* ─── Toggle switch ──────────────────────────────────────────────────────── */
.toggle-wrap { display: flex; align-items: center; gap: 10px; }
.toggle { position: relative; width: 44px; height: 24px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider { position: absolute; inset: 0; background: #cbd5e1; border-radius: 999px; transition: background .2s; cursor: pointer; }
.toggle-slider::before { content: ''; position: absolute; left: 3px; top: 3px; width: 18px; height: 18px; background: #fff; border-radius: 50%; transition: transform .2s; }
.toggle input:checked + .toggle-slider { background: var(--color-success); }
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); }

/* ─── Session timeout modal ──────────────────────────────────────────────── */
.session-modal { display: none; position: fixed; bottom: 20px; right: 20px; background: #fff; border: 1px solid var(--color-border); border-radius: var(--radius); box-shadow: var(--shadow-md); padding: 16px 20px; z-index: 9999; max-width: 320px; width: 90%; }
.session-modal.visible { display: block; }
.session-modal h4 { font-size: .9rem; margin-bottom: 8px; color: var(--color-warning); }
.session-modal p { font-size: .85rem; margin-bottom: 12px; color: var(--color-muted); }

/* ─── Misc ────────────────────────────────────────────────────────────────── */
.text-muted { color: var(--color-muted); }
.text-danger { color: var(--color-danger); }
.text-success { color: var(--color-success); }
.text-right { text-align: right; }
.mt-1 { margin-top: 4px; } .mt-2 { margin-top: 8px; } .mt-3 { margin-top: 16px; } .mt-4 { margin-top: 24px; }
.mb-1 { margin-bottom: 4px; } .mb-2 { margin-bottom: 8px; } .mb-3 { margin-bottom: 16px; } .mb-4 { margin-bottom: 24px; }
.gap-2 { gap: 8px; }
.d-flex { display: flex; } .align-center { align-items: center; } .justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
.w-100 { width: 100%; }
.hidden { display: none !important; }
.divider { border: none; border-top: 1px solid var(--color-border); margin: 20px 0; }
.pagination { display: flex; gap: 4px; align-items: center; margin-top: 16px; flex-wrap: wrap; }
.pagination a, .pagination span { display: inline-block; padding: 6px 10px; border: 1px solid var(--color-border); border-radius: var(--radius); font-size: .85rem; color: var(--color-text); }
.pagination a:hover { background: #f1f5f9; text-decoration: none; }
.pagination .current { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }

/* ─── Detail rows ─────────────────────────────────────────────────────────── */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0; }
@media (max-width: 600px) { .detail-grid { grid-template-columns: 1fr; } }
.detail-row { padding: 10px 16px; border-bottom: 1px solid var(--color-border); display: flex; flex-direction: column; gap: 2px; }
.detail-row:last-child { border-bottom: none; }
.detail-label { font-size: .78rem; font-weight: 600; color: var(--color-muted); text-transform: uppercase; letter-spacing: .05em; }
.detail-value { font-size: .9rem; }

/* ─── Login page ──────────────────────────────────────────────────────────── */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; background: var(--color-bg); }
.login-card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: 10px; box-shadow: var(--shadow-md); padding: 40px; width: 100%; max-width: 400px; }
.login-card h1 { font-size: 1.5rem; font-weight: 700; margin-bottom: 4px; }
.login-card .tagline { color: var(--color-muted); font-size: .9rem; margin-bottom: 28px; }

/* ─── Responsive table helpers ───────────────────────────────────────────── */
@media (max-width: 640px) {
  .hide-mobile { display: none !important; }
  .main-content { padding: 16px 12px; }
}
@media (max-width: 900px) {
  .hide-tablet { display: none !important; }
}
