:root {
  --primary: #1565C0;
  --secondary: #1976D2;
  --bg: #F5F7FA;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: 'Vazirmatn', Tahoma, sans-serif;
  direction: rtl;
  color: #1E293B;
  background: var(--bg);
}

a { text-decoration: none; color: inherit; }

/* Logo */
.kdt-logo { display: flex; align-items: center; gap: 10px; }
.kdt-logo-mark {
  width: 40px; height: 40px; border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 14px; letter-spacing: 0.5px;
  box-shadow: 0 4px 10px rgba(21,101,192,0.28);
}
.kdt-logo-mark-lg { width: 56px; height: 56px; font-size: 18px; border-radius: 14px; }
.kdt-logo-text { display: flex; flex-direction: column; line-height: 1.3; text-align: right; }
.kdt-logo-title { font-weight: 700; font-size: 14.5px; color: #16324F; }
.kdt-logo-sub { font-size: 10.5px; color: #8B9AAE; letter-spacing: 0.3px; }

/* Login / centered auth pages */
.page-shell { min-height: 100vh; display: flex; flex-direction: column; align-items: center;
  background: linear-gradient(180deg, #EAF2FB 0%, #F5F7FA 55%); }
.login-topbar { display: flex; justify-content: center; padding: 36px 20px 10px; }
.login-card-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 20px; width: 100%; }
.login-card {
  background: #fff; width: 100%; max-width: 400px; border-radius: 18px;
  padding: 34px 30px; box-shadow: 0 20px 45px -20px rgba(21,101,192,0.35), 0 2px 8px rgba(16,42,67,0.06);
}
.login-card-head { text-align: center; margin-bottom: 22px; }
.login-icon-badge {
  width: 54px; height: 54px; border-radius: 50%; margin: 0 auto 14px; font-size: 24px;
  background: #E3F2FD; color: var(--primary); display: flex; align-items: center; justify-content: center;
}
.login-card-head h1 { font-size: 19px; font-weight: 700; margin: 0 0 6px; color: #16324F; }
.login-card-head p { font-size: 13px; color: #7C8A9C; margin: 0; line-height: 1.8; }
.login-form { display: flex; flex-direction: column; gap: 16px; margin-top: 6px; }
.login-footnote { margin-top: 22px; font-size: 12px; color: #9AA7B8; }

/* Fields */
.field-group { display: flex; flex-direction: column; gap: 7px; }
.field-group label { font-size: 13px; font-weight: 600; color: #374C63; }
.req { color: #D32F2F; }
.field-hint { font-size: 11.5px; color: #94A3B8; }
input[type=text], input[type=password], input[type=tel], input[type=search], textarea, select {
  width: 100%; border: 1.5px solid #E1E7EF; background: #FAFBFD; border-radius: 10px;
  padding: 11px 14px; font-size: 14px; color: #1E293B; font-family: inherit;
  transition: border-color 0.18s, box-shadow 0.18s, background 0.18s;
}
textarea { resize: vertical; min-height: 110px; }
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--primary); background: #fff;
  box-shadow: 0 0 0 3.5px rgba(21,101,192,0.12);
}
.input-error { border-color: #E53935 !important; }
.error-text { font-size: 12px; color: #E53935; display: block; margin-top: 4px; }
.alert-error, .alert-success {
  display: flex; align-items: center; gap: 8px; border-radius: 10px; padding: 10px 12px; font-size: 13px;
}
.alert-error { background: #FDECEC; color: #C62828; border: 1px solid #F5C6C6; }
.alert-success { background: #E8F5E9; color: #2E7D32; border: 1px solid #C8E6C9; }

/* Buttons */
.btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: linear-gradient(135deg, var(--primary), var(--secondary)); color: #fff;
  border: none; border-radius: 10px; padding: 11px 20px; font-size: 14px; font-weight: 600;
  cursor: pointer; box-shadow: 0 8px 18px -8px rgba(21,101,192,0.55); font-family: inherit;
}
.btn-primary:hover { opacity: 0.94; }
.btn-block { width: 100%; }
.btn-secondary {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: #fff; color: var(--primary); border: 1.5px solid #D6E4F5; border-radius: 10px;
  padding: 10px 18px; font-size: 14px; font-weight: 600; cursor: pointer; font-family: inherit;
}
.btn-secondary:hover { background: #EEF5FC; }
.btn-danger {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: linear-gradient(135deg, #E53935, #C62828); color: #fff; border: none; border-radius: 10px;
  padding: 10px 18px; font-size: 14px; font-weight: 600; cursor: pointer; font-family: inherit;
}
.link-btn {
  display: inline-flex; align-items: center; gap: 4px; background: none; border: none;
  color: var(--primary); font-size: 13px; font-weight: 600; cursor: pointer; font-family: inherit;
}
.icon-btn-danger {
  display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px;
  border-radius: 8px; border: 1.5px solid #FADCDC; background: #FEF6F6; color: #D32F2F; cursor: pointer;
  font-size: 15px;
}

/* App shell */
.app-shell { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  height: 64px; background: #fff; border-bottom: 1px solid #E7ECF3; display: flex; align-items: center;
  padding: 0 18px; position: sticky; top: 0; z-index: 30; box-shadow: 0 1px 3px rgba(16,42,67,0.04);
}
.topbar-center { flex: 1; display: flex; justify-content: center; }
.topbar-spacer { width: 38px; }
.hamburger {
  display: none; background: #F1F5F9; border: none; border-radius: 9px; padding: 8px 12px; cursor: pointer;
  color: #374C63; font-size: 16px;
}
.app-body { flex: 1; display: flex; }

/* Sidebar */
.sidebar {
  width: 250px; background: #fff; border-left: 1px solid #E7ECF3; display: flex; flex-direction: column;
  padding: 22px 16px; gap: 14px; flex-shrink: 0;
}
.sidebar-user { display: flex; align-items: center; gap: 10px; padding: 0 6px; margin-bottom: 4px; }
.sidebar-avatar {
  width: 40px; height: 40px; border-radius: 50%; background: #E3F2FD;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: 18px;
}
.sidebar-user-name { font-size: 13.5px; font-weight: 700; color: #16324F; margin-bottom: 3px; }
.role-badge { display: inline-flex; align-items: center; font-size: 10.5px; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.role-badge-admin { background: #FFF3E0; color: #B15E00; }
.role-badge-staff { background: #E3F2FD; color: #1565C0; }
.role-badge-qual { background: #F3E5F5; color: #7B1FA2; }
.sidebar-nav { display: flex; flex-direction: column; gap: 5px; }
.sidebar-link {
  display: flex; align-items: center; gap: 11px; padding: 11px 14px; border-radius: 10px;
  color: #4B5C70; font-size: 14px; font-weight: 600; text-align: right;
}
.sidebar-link:hover { background: #F1F6FC; color: var(--primary); }
.sidebar-link-active { background: linear-gradient(135deg, var(--primary), var(--secondary)); color: #fff; }
.sidebar-link-active:hover { color: #fff; }
.sidebar-divider { height: 1px; background: #EEF1F6; margin: 4px 0; flex-shrink: 0; }
.sidebar-logout {
  display: flex; align-items: center; gap: 11px; padding: 11px 14px; border-radius: 10px;
  border: 1.5px solid #FADCDC; background: #FEF6F6; color: #D32F2F; font-size: 14px; font-weight: 600;
  margin-top: auto;
}
.sidebar-logout:hover { background: #FCE9E9; }
.sidebar-scrim { display: none; }

/* Main content */
.main-content { flex: 1; padding: 26px 30px; max-width: 100%; overflow-x: hidden; }
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-header h2 { font-size: 21px; font-weight: 800; color: #16324F; margin: 0 0 4px; }
.page-subtitle { font-size: 13.5px; color: #8593A6; margin: 0; }

/* Cards */
.card { background: #fff; border-radius: 16px; padding: 22px; box-shadow: 0 4px 18px -8px rgba(16,42,67,0.08); border: 1px solid #EEF1F6; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; flex-wrap: wrap; gap: 8px; }
.card-head h3 { font-size: 15.5px; font-weight: 700; color: #22364C; margin: 0; }

/* Stats */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 22px; }
.stat-card {
  background: #fff; border-radius: 16px; padding: 18px; display: flex; align-items: center; gap: 14px;
  box-shadow: 0 4px 18px -8px rgba(16,42,67,0.08); border: 1px solid #EEF1F6;
}
.stat-icon { width: 46px; height: 46px; border-radius: 12px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: 20px; }
.stat-value { font-size: 21px; font-weight: 800; color: #16324F; line-height: 1.2; }
.stat-label { font-size: 12.5px; color: #8593A6; }

/* Recent list */
.recent-list { display: flex; flex-direction: column; gap: 8px; }
.recent-item { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; background: #F8FAFC; border-radius: 11px; gap: 10px; flex-wrap: wrap; }
.recent-item-main { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.recent-id { font-weight: 700; color: var(--primary); font-size: 13px; }
.recent-name { font-weight: 600; color: #22364C; font-size: 13.5px; }
.recent-org { color: #8593A6; font-size: 12.5px; }

/* Empty state */
.empty-state { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 50px 0; color: #A6B2C2; }
.empty-state p { font-size: 13.5px; margin: 0; }

/* Form sections (new ticket) */
.form-grid { display: flex; flex-direction: column; gap: 18px; }
.section-card { max-width: 680px; }
.section-title { display: flex; align-items: center; gap: 8px; font-size: 14.5px; font-weight: 700; color: #16324F; margin: 0 0 14px; }
.section-num { width: 24px; height: 24px; border-radius: 50%; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; flex-shrink: 0; }
.conditional-field { background: #F5F9FF; border-radius: 12px; padding: 14px; border: 1px dashed #C7DCF4; }
.form-actions { display: flex; align-items: center; justify-content: space-between; margin-top: 6px; gap: 10px; flex-wrap: wrap; }

/* Success panel */
.success-panel { background: #fff; border-radius: 18px; padding: 46px 30px; text-align: center; max-width: 480px; margin: 20px auto; box-shadow: 0 4px 18px -8px rgba(16,42,67,0.08); border: 1px solid #EEF1F6; }
.success-icon { width: 74px; height: 74px; border-radius: 50%; background: #E8F5E9; color: #2E7D32; font-size: 34px; display: flex; align-items: center; justify-content: center; margin: 0 auto 18px; }
.success-panel h2 { font-size: 19px; font-weight: 800; color: #16324F; margin: 0 0 8px; }
.success-panel p { font-size: 14px; color: #66748A; margin: 0 0 22px; }
.success-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* Product checkbox-pill grid (no JS required) */
.pill-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.pill-checkbox { position: absolute; opacity: 0; width: 1px; height: 1px; }
.pill-label {
  display: inline-flex; align-items: center; border: 1.5px solid #E1E7EF; background: #FAFBFD; color: #4B5C70;
  border-radius: 999px; padding: 8px 16px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.pill-checkbox:checked + .pill-label { background: linear-gradient(135deg, var(--primary), var(--secondary)); color: #fff; border-color: transparent; }
.pill-checkbox:focus-visible + .pill-label { box-shadow: 0 0 0 3px rgba(21,101,192,0.3); }

/* Referral radio pills */
.referral-pills { display: flex; flex-wrap: wrap; gap: 8px; }
.referral-badge { display: inline-flex; font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 999px; }
.referral-badge-qual { background: #F3E5F5; color: #7B1FA2; }
.referral-badge-warranty { background: #E0F2F1; color: #00695C; }

/* Conditional field reveal (progressive enhancement via JS; visible by default) */
.js-conditional.js-hidden { display: none; }

/* Tables */
.list-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.search-box { flex: 1; min-width: 240px; }
.search-box form { display: flex; gap: 8px; }
.table-scroll { overflow-x: auto; }
.ticket-table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 1080px; }
.ticket-table thead th { text-align: right; padding: 11px 12px; background: #F5F8FC; color: #66748A; font-weight: 700; font-size: 12px; border-bottom: 1.5px solid #E7ECF3; white-space: nowrap; }
.ticket-table tbody td { padding: 12px; border-bottom: 1px solid #F0F3F7; color: #374C63; vertical-align: middle; }
.ticket-table tbody tr:hover { background: #FAFCFF; }
.mono-cell { font-weight: 600; color: #16324F; }
.nowrap-cell { white-space: nowrap; }
.firmware-cell { white-space: nowrap; font-size: 12px; color: #4B5C70; }
.reason-cell { max-width: 260px; }
.tag-list { display: flex; flex-wrap: wrap; gap: 5px; max-width: 220px; }
.tag { background: #EEF3FA; color: #375A85; font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 6px; white-space: nowrap; }
.status-badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; padding: 5px 10px; border-radius: 999px; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; }
.status-select { border: none; border-radius: 999px; padding: 6px 10px; font-size: 12px; font-weight: 700; cursor: pointer; font-family: inherit; }
.password-status { font-size: 11.5px; font-weight: 700; padding: 3px 9px; border-radius: 999px; }
.password-status-active { background: #E8F5E9; color: #2E7D32; }
.password-status-pending { background: #FFF3E0; color: #B15E00; }

.referral-cell { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.qual-substatus { font-size: 10.5px; font-weight: 700; padding: 2px 7px; border-radius: 999px; white-space: nowrap; }
.qual-substatus-pending { background: #FFF3E0; color: #B15E00; }
.qual-substatus-answered { background: #EDE7F6; color: #5E35B1; }
.qual-substatus-confirmed { background: #E8F5E9; color: #2E7D32; }
.qual-lock-note { font-size: 10.5px; color: #B15E00; margin-top: 5px; white-space: nowrap; }

/* Confirmation pages (delete / qual review) replace JS modals */
.confirm-card { max-width: 460px; margin: 0 auto; }
.confirm-icon { width: 46px; height: 46px; border-radius: 12px; background: #FEF6F6; color: #D32F2F; display: flex; align-items: center; justify-content: center; margin-bottom: 12px; font-size: 20px; }
.confirm-icon-purple { background: #F3E5F5; color: #7B1FA2; }
.confirm-card h3 { font-size: 16px; font-weight: 700; color: #16324F; margin: 0 0 8px; }
.confirm-desc { font-size: 13px; color: #7C8A9C; margin: 0 0 14px; line-height: 1.7; }
.confirm-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.qual-answer-box { background: #F8F5FC; border: 1px solid #E4D9F2; border-radius: 10px; padding: 12px 14px; font-size: 13.5px; color: #4B3B63; line-height: 1.8; white-space: pre-wrap; margin-bottom: 10px; }
.qual-answered-meta { font-size: 11.5px; color: #9AA7B8; margin: 0 0 14px; }

/* Report */
.category-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.category-card {
  display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 26px 16px;
  border-radius: 14px; border: 1.5px solid #E7ECF3; background: #F8FAFC; cursor: pointer;
  font-size: 14px; font-weight: 700; color: #22364C;
}
.category-card:hover { border-color: var(--primary); background: #F0F6FD; }
.category-card.active { border-color: var(--primary); background: #E3F2FD; }
.category-icon { width: 52px; height: 52px; border-radius: 50%; background: #E3F2FD; color: var(--primary); display: flex; align-items: center; justify-content: center; font-size: 22px; }
.report-summary { font-size: 13px; color: #8593A6; margin: 0 0 16px; }
.report-bars { display: flex; flex-direction: column; gap: 12px; }
.report-bar-row { display: flex; align-items: center; gap: 12px; }
.report-rank-badge { width: 26px; height: 26px; border-radius: 50%; background: #EAF0F7; color: #1565C0; font-size: 12px; font-weight: 800; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.report-bar-main { flex: 1; }
.report-bar-label { display: flex; align-items: center; justify-content: space-between; margin-bottom: 5px; }
.report-version { font-size: 13.5px; font-weight: 700; color: #22364C; }
.report-count { font-size: 12px; color: #8593A6; }
.report-bar-track { height: 9px; border-radius: 999px; background: #EEF2F7; overflow: hidden; }
.report-bar-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--primary), var(--secondary)); }

/* Qual dashboard */
.qual-tabs { display: flex; gap: 8px; margin-bottom: 18px; }
.qual-tab { display: inline-flex; align-items: center; gap: 8px; border: 1.5px solid #E1E7EF; background: #fff; color: #4B5C70; border-radius: 10px; padding: 9px 16px; font-size: 13.5px; font-weight: 700; }
.qual-tab.active { background: linear-gradient(135deg, var(--primary), var(--secondary)); color: #fff; border-color: transparent; }
.qual-tab-count { background: #EEF1F6; color: #66748A; border-radius: 999px; font-size: 11.5px; padding: 1px 8px; }
.qual-tab.active .qual-tab-count { background: rgba(255,255,255,0.25); color: #fff; }
.qual-list { display: flex; flex-direction: column; gap: 16px; }
.qual-card { max-width: 720px; }
.qual-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.qual-customer { font-size: 15px; font-weight: 700; color: #16324F; margin: 4px 0 0; }
.qual-meta { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; flex-wrap: wrap; }
.qual-meta-item { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; color: #66748A; }
.qual-firmware { font-size: 12.5px; color: #4B5C70; margin: 0 0 10px; }
.qual-desc-label { font-size: 12.5px; font-weight: 700; color: #66748A; margin: 0 0 4px; }
.qual-desc-text { font-size: 13.5px; color: #374C63; background: #F8FAFC; border-radius: 10px; padding: 12px 14px; margin: 0 0 16px; line-height: 1.8; }
.qual-confirmed-meta, .qual-answered-note { font-size: 12.5px; color: #2E7D32; background: #E8F5E9; border-radius: 10px; padding: 10px 12px; margin: 0; line-height: 1.7; }
.qual-answered-note { color: #5E35B1; background: #EDE7F6; }

/* Responsive */
@media (max-width: 1024px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .category-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 860px) {
  .hamburger { display: flex; align-items: center; justify-content: center; }
  .sidebar { position: fixed; top: 64px; bottom: 0; right: -270px; z-index: 40; width: 250px; transition: right 0.25s ease; box-shadow: -8px 0 24px rgba(16,42,67,0.12); overflow-y: auto; }
  .sidebar.open { right: 0; }
  .sidebar-scrim.show { display: block; position: fixed; inset: 64px 0 0 0; background: rgba(16,42,67,0.35); z-index: 35; }
  .main-content { padding: 18px 16px; }
  .kdt-logo-sub { display: none; }
  .category-grid { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .stat-grid { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; align-items: stretch; }
  .page-header .btn-primary { width: 100%; justify-content: center; }
  .success-actions { flex-direction: column; }
  .success-actions .btn-primary, .success-actions .btn-secondary { width: 100%; }
  .recent-item { flex-direction: column; align-items: flex-start; }
  .login-card { padding: 26px 20px; }
  .confirm-actions { flex-direction: column-reverse; }
  .confirm-actions button, .confirm-actions a { width: 100%; text-align: center; }
}
