/* === BASE RESET === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
}
body {
  min-height: 100dvh;
  line-height: 1.6;
  font-family: 'Satoshi', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 15px;
}
img, svg { display: block; max-width: 100%; }
button { cursor: pointer; background: none; border: none; font: inherit; }
table { border-collapse: collapse; width: 100%; }

/* === DESIGN TOKENS === */
:root, [data-theme="light"] {
  --bg: #f5f5f0;
  --surface: #ffffff;
  --surface-2: #fafaf7;
  --border: #e2e0db;
  --border-light: #eeecea;
  --text: #1a1a1a;
  --text-muted: #6b6b65;
  --text-faint: #a3a39d;
  --accent: #0e6b70;
  --accent-light: #e8f4f4;
  --red: #c9363c;
  --red-bg: #fef2f2;
  --red-border: #fecaca;
  --orange: #c2590a;
  --orange-bg: #fff7ed;
  --orange-border: #fed7aa;
  --yellow: #a16207;
  --yellow-bg: #fefce8;
  --yellow-border: #fde68a;
  --blue: #1d68a7;
  --blue-bg: #eff6ff;
  --blue-border: #bfdbfe;
  --green: #16803c;
  --green-bg: #f0fdf4;
  --green-border: #bbf7d0;
  --gray: #6b7280;
  --gray-bg: #f3f4f6;
  --gray-border: #d1d5db;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
  --radius: 10px;
  --radius-sm: 6px;
}

[data-theme="dark"] {
  --bg: #131311;
  --surface: #1c1c19;
  --surface-2: #222220;
  --border: #2e2e2b;
  --border-light: #262624;
  --text: #d4d4cf;
  --text-muted: #8a8a84;
  --text-faint: #5a5a55;
  --accent: #4fb8be;
  --accent-light: #1a2e2f;
  --red: #ef6b6b;
  --red-bg: #2a1515;
  --red-border: #4a2020;
  --orange: #f0923e;
  --orange-bg: #2a1d10;
  --orange-border: #4a3018;
  --yellow: #eab308;
  --yellow-bg: #2a2510;
  --yellow-border: #4a3f18;
  --blue: #60a5fa;
  --blue-bg: #121d2e;
  --blue-border: #1e3a5f;
  --green: #4ade80;
  --green-bg: #0f2318;
  --green-border: #1a3f28;
  --gray: #9ca3af;
  --gray-bg: #1f2024;
  --gray-border: #374151;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.3);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131311;
    --surface: #1c1c19;
    --surface-2: #222220;
    --border: #2e2e2b;
    --border-light: #262624;
    --text: #d4d4cf;
    --text-muted: #8a8a84;
    --text-faint: #5a5a55;
    --accent: #4fb8be;
    --accent-light: #1a2e2f;
    --red: #ef6b6b;
    --red-bg: #2a1515;
    --red-border: #4a2020;
    --orange: #f0923e;
    --orange-bg: #2a1d10;
    --orange-border: #4a3018;
    --yellow: #eab308;
    --yellow-bg: #2a2510;
    --yellow-border: #4a3f18;
    --blue: #60a5fa;
    --blue-bg: #121d2e;
    --blue-border: #1e3a5f;
    --green: #4ade80;
    --green-bg: #0f2318;
    --green-border: #1a3f28;
    --gray: #9ca3af;
    --gray-bg: #1f2024;
    --gray-border: #374151;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.2);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.3);
  }
}

body {
  background: var(--bg);
  color: var(--text);
}

/* === HEADER === */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 24px 0;
}
.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}
.header-brand {
  display: flex;
  align-items: center;
  gap: 14px;
}
.logo { color: var(--accent); flex-shrink: 0; }
.header-title {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.2;
  color: var(--text);
}
.header-subtitle {
  font-size: 14px;
  color: var(--accent);
  font-weight: 600;
  margin-top: 2px;
}
.header-meta {
  text-align: right;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}
.report-period {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.report-generated {
  font-size: 12px;
  color: var(--text-muted);
}
.theme-toggle {
  margin-top: 6px;
  padding: 6px;
  border-radius: 6px;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
}
.theme-toggle:hover {
  background: var(--surface-2);
  color: var(--text);
}

/* === MAIN === */
.main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 24px 64px;
}

/* === KPI CARDS === */
.kpi-section { margin-bottom: 36px; }
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}
.kpi-value {
  font-size: 32px;
  font-weight: 700;
  line-height: 1.1;
  margin-bottom: 4px;
}
.kpi-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.kpi-card.act-now { border-left: 4px solid var(--red); }
.kpi-card.act-now .kpi-value { color: var(--red); }
.kpi-card.neotech { border-left: 4px solid var(--orange); }
.kpi-card.neotech .kpi-value { color: var(--orange); }
.kpi-card.open { border-left: 4px solid var(--blue); }
.kpi-card.open .kpi-value { color: var(--blue); }
.kpi-card.resolved { border-left: 4px solid var(--green); }
.kpi-card.resolved .kpi-value { color: var(--green); }
.kpi-card.stale { border-left: 4px solid var(--yellow); }
.kpi-card.stale .kpi-value { color: var(--yellow); }

/* === SECTIONS === */
.section {
  margin-bottom: 40px;
}
.section-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--text);
}
.section-desc {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 20px;
  max-width: 600px;
}

/* === INSIGHTS === */
.insights-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.insight-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 14px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  line-height: 1.5;
}
.insight-icon {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  margin-top: 1px;
}
.insight-icon.alert { background: var(--red-bg); color: var(--red); border: 1px solid var(--red-border); }
.insight-icon.warn { background: var(--orange-bg); color: var(--orange); border: 1px solid var(--orange-border); }
.insight-icon.info { background: var(--blue-bg); color: var(--blue); border: 1px solid var(--blue-border); }
.insight-icon.success { background: var(--green-bg); color: var(--green); border: 1px solid var(--green-border); }

/* === ATTENTION CARDS === */
.tickets-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 14px;
}
.ticket-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.ticket-card.urgency-act_now { border-left: 4px solid var(--red); }
.ticket-card.urgency-neotech_action { border-left: 4px solid var(--orange); }
.ticket-card.urgency-stale { border-left: 4px solid var(--yellow); }
.ticket-card.urgency-monitor { border-left: 4px solid var(--blue); }

.ticket-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}
.ticket-card-id {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
  padding: 2px 8px;
  background: var(--accent-light);
  border-radius: 4px;
  white-space: nowrap;
  transition: opacity 0.15s;
}
.ticket-card-id:hover { opacity: 0.7; }
.ticket-card-status {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
  white-space: nowrap;
}
.status-client-reply { background: var(--red-bg); color: var(--red); border: 1px solid var(--red-border); }
.status-waiting-neotech { background: var(--orange-bg); color: var(--orange); border: 1px solid var(--orange-border); }
.status-waiting-client { background: var(--yellow-bg); color: var(--yellow); border: 1px solid var(--yellow-border); }
.status-in-progress { background: var(--blue-bg); color: var(--blue); border: 1px solid var(--blue-border); }
.status-on-hold { background: var(--gray-bg); color: var(--gray); border: 1px solid var(--gray-border); }
.status-resolved { background: var(--green-bg); color: var(--green); border: 1px solid var(--green-border); }

.ticket-card-subject {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
  color: var(--text);
}
.ticket-card-requester {
  font-size: 12px;
  color: var(--text-muted);
}
.ticket-card-insight {
  font-size: 13px;
  line-height: 1.55;
  color: var(--text-muted);
  padding: 10px 12px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
}
.ticket-card-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--text-faint);
  padding-top: 8px;
  border-top: 1px solid var(--border-light);
}
.ticket-card-assignee { font-weight: 500; color: var(--text-muted); }

/* === TABLES === */
.tickets-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.tickets-table {
  font-size: 13px;
}
.tickets-table thead {
  background: var(--surface-2);
}
.tickets-table th {
  padding: 12px 14px;
  text-align: left;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.tickets-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: top;
  line-height: 1.5;
}
.tickets-table tbody tr:last-child td {
  border-bottom: none;
}
.tickets-table tbody tr:hover {
  background: var(--surface-2);
}
.tickets-table .ticket-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  white-space: nowrap;
}
.tickets-table .ticket-link:hover { text-decoration: underline; }
.tickets-table .insight-cell {
  max-width: 320px;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
}
.tickets-table .status-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
  white-space: nowrap;
}
.tickets-table .waiting-cell {
  white-space: nowrap;
  font-size: 12px;
}

/* === WORKLOAD === */
.workload-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}
.workload-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-sm);
}
.workload-name {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 8px;
}
.workload-count {
  font-size: 28px;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
  margin-bottom: 6px;
}
.workload-count-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.workload-bar {
  margin-top: 12px;
  height: 6px;
  background: var(--border-light);
  border-radius: 3px;
  overflow: hidden;
}
.workload-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.5s ease;
}

/* === FOOTER === */
.footer {
  text-align: center;
  padding: 24px;
  font-size: 12px;
  color: var(--text-faint);
  border-top: 1px solid var(--border);
  margin-top: 40px;
}
.footer a {
  color: var(--text-faint);
  text-decoration: none;
  display: block;
  margin-top: 4px;
}
.footer a:hover { text-decoration: underline; }

/* === RESPONSIVE === */
@media (max-width: 768px) {
  .header-inner {
    flex-direction: column;
    align-items: flex-start;
  }
  .header-meta {
    align-items: flex-start;
    text-align: left;
    flex-direction: row;
    gap: 12px;
    flex-wrap: wrap;
  }
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .tickets-grid {
    grid-template-columns: 1fr;
  }
  .main {
    padding: 20px 16px 48px;
  }
}

@media (max-width: 480px) {
  .kpi-grid {
    grid-template-columns: 1fr;
  }
}
