:root {
  --primary: #1a4b8c;
  --primary-h: #153a6e;
  --accent: #2563eb;
  --purple: #7c3aed;
  --green: #16a34a;
  --amber: #d97706;
  --red: #dc2626;
  --gray-50: #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-400: #94a3b8;
  --gray-500: #64748b;
  --gray-700: #334155;
  --gray-900: #0f172a;
  --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,.05);
  --r: 8px;
  --r-sm: 4px;
  --blue-50: #f0f4ff;
  --row-edit-bg: #f0f4ff;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: system-ui, -apple-system, sans-serif; background: var(--gray-50); color: var(--gray-900); line-height: 1.5; }

/* Layout */
.container { max-width: 1100px; margin: 0 auto; padding: 0 1.5rem; }

/* Navbar */
.navbar { background: var(--primary); height: 56px; display: flex; align-items: center; padding: 0 1.5rem; gap: 2rem; box-shadow: var(--shadow-md); }
.navbar-brand { font-weight: 700; font-size: 1.05rem; color: #fff; text-decoration: none; white-space: nowrap; }
.navbar-nav { display: flex; gap: 0.15rem; }
.navbar-nav a { color: rgba(255,255,255,.8); text-decoration: none; padding: 0.35rem 0.75rem; border-radius: var(--r-sm); font-size: .875rem; transition: all .15s; }
.navbar-nav a:hover, .navbar-nav a.active { color: #fff; background: rgba(255,255,255,.18); }
.navbar-right { margin-left: auto; display: flex; align-items: center; gap: 1.25rem; font-size: .875rem; color: rgba(255,255,255,.8); }
.navbar-right a { color: rgba(255,255,255,.8); text-decoration: none; }
.navbar-right a:hover { color: #fff; }
.navbar-right span { color: rgba(255,255,255,.6); }

/* Agent layout */
.app-layout { display: flex; min-height: calc(100vh - 56px); }
.sidebar { width: 185px; background: #fff; border-right: 1px solid var(--gray-200); padding: 1.25rem 0.5rem; flex-shrink: 0; }
.sidebar-label { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--gray-400); padding: 0 0.5rem; margin: 1rem 0 0.4rem; }
.sidebar-label:first-child { margin-top: 0; }
.sidebar a { display: flex; align-items: center; gap: 0.5rem; padding: 0.4rem 0.5rem; border-radius: var(--r-sm); color: var(--gray-700); text-decoration: none; font-size: .8rem; transition: all .15s; margin-bottom: 0.1rem; }
.sidebar a:hover, .sidebar a.active { background: #eff6ff; color: var(--primary); font-weight: 500; }
.main { flex: 1; padding: 1.5rem; overflow-y: auto; min-width: 0; }

/* Page header */
.page-hd { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 1.5rem; }
.page-title { font-size: 1.35rem; font-weight: 700; }
.page-sub { font-size: .875rem; color: var(--gray-500); margin-top: .2rem; }

/* Cards */
.card { background: #fff; border-radius: var(--r); box-shadow: var(--shadow); padding: 1.25rem; }
.card-title { font-size: 1rem; font-weight: 600; color: var(--gray-700); margin-bottom: 1rem; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat { background: #fff; border-radius: var(--r); padding: 1.1rem 1.25rem; box-shadow: var(--shadow); }
.stat-btn { cursor: pointer; transition: transform .1s, box-shadow .1s; user-select: none; }
.stat-btn:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,.12); }
.stat-btn:active { transform: translateY(0); }
.stat-label { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--gray-500); margin-bottom: .4rem; }
.stat-value { font-size: 1.7rem; font-weight: 700; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: .4rem; padding: .45rem .9rem; border-radius: var(--r-sm); border: none; cursor: pointer; font-size: .875rem; font-weight: 500; transition: background .15s; text-decoration: none; white-space: nowrap; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-h); }
.btn-secondary { background: var(--gray-100); color: var(--gray-700); border: 1px solid var(--gray-200); }
.btn-secondary:hover { background: var(--gray-200); }
.btn-sm { padding: .25rem .6rem; font-size: .8rem; }
.btn-danger { background: var(--red); color: #fff; }

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-label { display: block; font-size: .875rem; font-weight: 500; color: var(--gray-700); margin-bottom: .35rem; }
.form-control { width: 100%; padding: .45rem .75rem; border: 1px solid var(--gray-200); border-radius: var(--r-sm); font-size: .875rem; background: #fff; transition: border-color .15s; font-family: inherit; color: var(--gray-900); }
.form-control:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37,99,235,.1); }
.form-control-sm { padding: .25rem .5rem; font-size: .8rem; width: auto; }
textarea.form-control { resize: vertical; min-height: 110px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

/* Filters */
.filters { display: flex; gap: .75rem; flex-wrap: wrap; margin-bottom: 1.25rem; align-items: center; }
.filters select, .filters input { padding: .38rem .7rem; border: 1px solid var(--gray-200); border-radius: var(--r-sm); font-size: .875rem; background: #fff; }
.filters input { min-width: 180px; }
.include-closed-label { display: flex; align-items: center; gap: .2rem; font-size: .8rem; color: var(--gray-500); cursor: pointer; user-select: none; margin-left: auto; }
.include-closed-label input[type=checkbox] { cursor: pointer; }
body.dark .include-closed-label { color: #94a3b8; }

/* Table */
.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .875rem; }
th { text-align: left; padding: .55rem .75rem; background: var(--gray-50); border-bottom: 2px solid var(--gray-200); font-weight: 600; color: var(--gray-500); text-transform: uppercase; font-size: .7rem; letter-spacing: .05em; white-space: nowrap; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--primary); }
td { padding: .6rem .75rem; border-bottom: 1px solid var(--gray-100); vertical-align: middle; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #f0f7ff; }

/* Badges */
.badge { display: inline-flex; align-items: center; padding: .15rem .55rem; border-radius: 999px; font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
.badge-open { background: #dbeafe; color: #1d4ed8; }
.badge-new { background: #dbeafe; color: #1d4ed8; }
.badge-with_customer { background: #cffafe; color: #0e7490; }
.badge-in_progress { background: #fef3c7; color: #b45309; }
.badge-resolved { background: #dcfce7; color: #15803d; }
.badge-closed { background: var(--gray-100); color: var(--gray-500); }
.overdue { color: #dc2626; font-weight: 600; }
.badge-support { background: #dbeafe; color: #1d4ed8; }
.badge-enhancement { background: #ede9fe; color: #6d28d9; }
.badge-low { background: var(--gray-100); color: var(--gray-500); }
.badge-medium { background: #dbeafe; color: #1d4ed8; }
.badge-high { background: #fef3c7; color: #b45309; }
.badge-critical { background: #fee2e2; color: #b91c1c; }
.badge-main { background: #fef3c7; color: #b45309; }

/* Alerts */
.alert { padding: .7rem 1rem; border-radius: var(--r-sm); font-size: .875rem; margin-bottom: 1rem; }
.alert-error { background: #fee2e2; color: #b91c1c; border: 1px solid #fecaca; }
.alert-success { background: #dcfce7; color: #15803d; border: 1px solid #bbf7d0; }

/* Auth */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--gray-50); padding: 1rem; }
.auth-card { background: #fff; border-radius: var(--r); box-shadow: var(--shadow-md); padding: 2rem; width: 100%; max-width: 480px; }
.auth-logo { text-align: center; margin-bottom: 1.5rem; }
.auth-logo h1 { font-size: 1.4rem; font-weight: 800; color: var(--primary); }
.auth-logo p { color: var(--gray-500); font-size: .875rem; margin-top: .2rem; }
.auth-card h2 { font-size: 1rem; font-weight: 600; margin-bottom: 1.25rem; color: var(--gray-700); }
.auth-foot { text-align: center; margin-top: 1rem; font-size: .8rem; color: var(--gray-500); }
.auth-foot a { color: var(--primary); text-decoration: none; font-weight: 500; }

/* Landing */
.landing { min-height: 100vh; background: linear-gradient(145deg, #0f2d5a 0%, #1a4b8c 50%, #2563eb 100%); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 2rem; }
.landing h1 { color: #fff; font-size: 2.4rem; font-weight: 800; text-align: center; margin-bottom: .5rem; }
.landing-sub { color: rgba(255,255,255,.7); text-align: center; margin-bottom: 3rem; font-size: 1.05rem; }
.landing-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; width: 100%; max-width: 560px; }
.landing-card { background: #fff; border-radius: 12px; padding: 2rem 1.5rem; text-align: center; text-decoration: none; transition: transform .2s, box-shadow .2s; box-shadow: 0 4px 24px rgba(0,0,0,.18); }
.landing-card:hover { transform: translateY(-4px); box-shadow: 0 10px 36px rgba(0,0,0,.25); }
.landing-card-icon { font-size: 2.4rem; margin-bottom: .75rem; }
.landing-card-title { font-size: 1.05rem; font-weight: 700; color: var(--gray-900); margin-bottom: .35rem; }
.landing-card-desc { font-size: .8rem; color: var(--gray-500); }

/* Ticket detail */
.ticket-layout { display: grid; grid-template-columns: 1fr 300px; gap: 1.5rem; }
.meta-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; margin-bottom: 1.25rem; }
.meta-item label { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--gray-400); display: block; margin-bottom: .2rem; }
.meta-item .val { font-size: .875rem; color: var(--gray-700); }
.description-box { background: var(--gray-50); border: 1px solid var(--gray-200); border-radius: var(--r-sm); padding: 1rem; font-size: .875rem; color: var(--gray-700); white-space: pre-wrap; line-height: 1.6; margin-bottom: 1.5rem; }

/* Comments */
.comments { display: flex; flex-direction: column; gap: .75rem; margin-bottom: 1rem; }
.comment { padding: .875rem 1rem; border-radius: var(--r-sm); }
.comment.agent-comment { background: #eff6ff; border-left: 3px solid var(--primary); }
.comment.customer-comment { background: var(--gray-50); border-left: 3px solid var(--gray-300); }
.comment-meta { font-size: .75rem; color: var(--gray-400); margin-bottom: .4rem; }
.comment-meta strong { color: var(--gray-600); }
.comment-body { font-size: .875rem; color: var(--gray-700); white-space: pre-wrap; }

/* Edit panel */
.edit-panel { display: flex; flex-direction: column; gap: .75rem; }
.edit-panel label { font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--gray-500); display: block; margin-bottom: .25rem; }
.edit-panel select { width: 100%; padding: .45rem .7rem; border: 1px solid var(--gray-200); border-radius: var(--r-sm); font-size: .875rem; background: #fff; }

/* Empty / loading */
.empty { text-align: center; padding: 3rem 1rem; color: var(--gray-400); }
.empty-icon { font-size: 2.5rem; margin-bottom: .75rem; }
.loading { text-align: center; padding: 2rem; color: var(--gray-400); font-size: .875rem; }

/* Modal */
.modal-bg { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 100; align-items: center; justify-content: center; padding: 1rem; }
.modal-bg.open { display: flex; }
.modal { background: #fff; border-radius: var(--r); padding: 1.75rem; width: 100%; max-width: 620px; max-height: 90vh; display: flex; flex-direction: column; box-shadow: 0 20px 40px rgba(0,0,0,.15); }
.modal form { overflow-y: auto; flex: 1; padding-right: .25rem; }
.modal-hd { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.25rem; }
.modal-hd h3 { font-size: 1rem; font-weight: 600; }
.modal-close { background: none; border: none; cursor: pointer; color: var(--gray-400); font-size: 1.3rem; line-height: 1; }

/* Ticket ID */
.ticket-id { font-family: monospace; font-size: .8rem; color: var(--gray-400); }

/* Company link in ticket grid */
.co-link { color: var(--gray-700); font-weight: 500; text-decoration: none; }
.co-link:hover { text-decoration: underline; }
body.dark .co-link { color: #cbd5e1; }

.nav-badge { margin-left: auto; background: var(--primary); color: #fff; font-size: .65rem; font-weight: 700; padding: .1rem .38rem; border-radius: 99px; min-width: 1.2rem; text-align: center; line-height: 1.5; }
.nav-badge:empty { display: none; }
body.dark .nav-badge { background: #3b82f6; }

@media (max-width: 768px) {
  .landing-cards { grid-template-columns: 1fr; }
  .ticket-layout { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .stats { grid-template-columns: 1fr 1fr; }
  .form-row { grid-template-columns: 1fr; }
}

/* Dark theme */
body.dark { background: #0f172a; color: #e2e8f0; --blue-50: #1e3a5f; --row-edit-bg: #1e3a5f; }
body.dark .sidebar { background: #1e293b; border-right-color: #334155; }
body.dark .sidebar a { color: #94a3b8; }
body.dark .sidebar a:hover, body.dark .sidebar a.active { background: #1e3a5f; color: #93c5fd; }
body.dark .sidebar-label { color: #475569; }
body.dark .card { background: #1e293b; }
body.dark .card-title { color: #94a3b8; }
body.dark .stat { background: #1e293b; }
body.dark .stat-btn:hover { box-shadow: 0 4px 12px rgba(0,0,0,.35); }
body.dark .page-title { color: #f1f5f9; }
body.dark .page-sub { color: #94a3b8; }
body.dark th { background: #0f172a; border-bottom-color: #334155; color: #64748b; }
body.dark td { border-bottom-color: #1e293b; color: #e2e8f0; }
body.dark tr.clickable:hover td { background: #1e3a5f; }
body.dark .form-control { background: #0f172a; color: #e2e8f0; border-color: #334155; }
body.dark .form-control:focus { border-color: #3b82f6; }
body.dark .form-label { color: #cbd5e1; }
body.dark .filters select, body.dark .filters input, body.dark .page-hd input { background: #0f172a; color: #e2e8f0; border-color: #334155; }
body.dark .edit-panel select { background: #0f172a; color: #e2e8f0; border-color: #334155; }
body.dark .edit-panel label { color: #94a3b8; }
body.dark .btn-secondary { background: #1e293b; color: #cbd5e1; border-color: #334155; }
body.dark .btn-secondary:hover { background: #253450; }
body.dark .modal-bg { background: rgba(0,0,0,.7); }
body.dark .modal { background: #1e293b; }
body.dark .modal-hd h3 { color: #f1f5f9; }
body.dark .modal-close { color: #475569; }
.att-file-row { padding: .5rem .75rem; background: var(--gray-50); border-radius: var(--r-sm); }
.att-file-name { font-size: .825rem; flex: 1; word-break: break-word; color: var(--gray-800); }
.att-file-meta { font-size: .72rem; color: var(--gray-400); }
body.dark .att-file-row { background: #162033; }
body.dark .att-file-name { color: #e2e8f0; }
body.dark .att-file-meta { color: #64748b; }
body.dark .description-box { background: #162033; border-color: #334155; color: #cbd5e1; }
body.dark .comment.agent-comment { background: #1e3a5f; border-left-color: #3b82f6; }
body.dark .comment.customer-comment { background: #162033; border-left-color: #475569; }
body.dark .comment-body { color: #cbd5e1; }
body.dark .comment-meta { color: #475569; }
body.dark .comment-meta strong { color: #94a3b8; }
body.dark .auth-card { background: #1e293b; }
body.dark .auth-card h2 { color: #e2e8f0; }
body.dark .auth-logo p { color: #64748b; }
body.dark .auth-foot { color: #475569; }
body.dark .meta-item .val { color: #cbd5e1; }
body.dark .meta-item label { color: #475569; }
body.dark .ticket-id { color: #475569; }
body.dark .loading, body.dark .empty { color: #475569; }
body.dark .rn-version-body { background: #1e293b; border-color: #334155; }
body.dark .rn-section-label { color: #93c5fd; border-bottom-color: #334155; }
body.dark .rn-item { border-bottom-color: #334155; }
body.dark .rn-item-body { color: #cbd5e1; }
