:root {
  color-scheme: light;
  --bg: #f3f6fa;
  --surface: #ffffff;
  --surface-soft: #f7f9fc;
  --surface-hover: #eef4ff;
  --text: #1c2530;
  --muted: #637083;
  --line: #dde5ee;
  --line-strong: #b9c6d3;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --blue: #2563eb;
  --amber: #a05a00;
  --red: #c0282d;
  --green: #137a46;
  --nav: #17202b;
  --shadow: 0 14px 35px rgba(16, 24, 40, 0.08);
  --focus: 0 0 0 3px rgba(37, 99, 235, 0.16);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111827;
  --surface: #16202c;
  --surface-soft: #1c2938;
  --surface-hover: #243447;
  --text: #e5edf5;
  --muted: #9aa8b7;
  --line: #334155;
  --line-strong: #4b5f74;
  --primary: #60a5fa;
  --primary-dark: #3b82f6;
  --blue: #7db7ff;
  --amber: #f4b860;
  --red: #ff8a8e;
  --green: #79d89d;
  --nav: #0f172a;
  --shadow: none;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  -webkit-font-smoothing: antialiased;
}

:root[data-theme="dark"] .views,
:root[data-theme="dark"] .ticket-list-panel,
:root[data-theme="dark"] .ticket-detail-panel,
:root[data-theme="dark"] .side-card,
:root[data-theme="dark"] input,
:root[data-theme="dark"] select,
:root[data-theme="dark"] textarea,
:root[data-theme="dark"] .message,
:root[data-theme="dark"] .secondary-button,
:root[data-theme="dark"] .icon-button,
:root[data-theme="dark"] .macro-chip,
:root[data-theme="dark"] .pill,
:root[data-theme="dark"] .tag,
:root[data-theme="dark"] .sidebar-stats,
:root[data-theme="dark"] .properties-panel {
  background: var(--surface);
  color: var(--text);
}

:root[data-theme="dark"] .brand-logo {
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35);
}

:root[data-theme="dark"] .button-icon {
  background: var(--surface-hover);
}

:root[data-theme="dark"] .status-new,
:root[data-theme="dark"] .status-open,
:root[data-theme="dark"] .priority-normal {
  background: #17385f;
}

:root[data-theme="dark"] .priority-high,
:root[data-theme="dark"] .status-pending,
:root[data-theme="dark"] .status-waiting-customer {
  background: #46320f;
}

:root[data-theme="dark"] .status-solved,
:root[data-theme="dark"] .status-closed,
:root[data-theme="dark"] .priority-low,
:root[data-theme="dark"] .review-good {
  background: #123d2a;
}

:root[data-theme="dark"] .priority-critical,
:root[data-theme="dark"] .review-bad {
  background: #4a1f24;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 272px minmax(0, 1fr);
  min-height: 100vh;
}

.rail {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 22px 12px;
  background: #ffffff;
  border-right: 1px solid var(--line);
}

.logo {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--nav);
  color: #ffffff;
  font-weight: 900;
}

.rail-button {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-weight: 900;
}

.rail-button.active,
.rail-button:hover {
  background: var(--nav);
  color: #ffffff;
}

.views {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 100vh;
  padding: 22px 16px;
  background: #ffffff;
  border-right: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--primary), #0f766e);
  color: #ffffff;
  box-shadow: 0 10px 24px rgba(37, 99, 235, 0.22);
}

.brand-logo svg {
  width: 25px;
  height: 25px;
}

.brand-logo path:first-child {
  fill: rgba(255, 255, 255, 0.2);
  stroke: #ffffff;
  stroke-width: 1.8;
}

.brand-logo path:last-child {
  fill: none;
  stroke: #ffffff;
  stroke-linecap: round;
  stroke-width: 2;
}

.brand h1,
.brand p,
.topbar h2,
.ticket-header h3,
.list-toolbar h3,
.side-card h3,
.mailbox-card p {
  margin: 0;
}

.brand h1 {
  font-size: 19px;
  letter-spacing: 0;
}

.brand p,
.mailbox-card p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.view-section {
  display: grid;
  gap: 8px;
}

.view-title,
.label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.view-group,
.property-group {
  display: grid;
  gap: 8px;
}

.view-group summary,
.property-group summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  list-style: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.view-group summary::-webkit-details-marker,
.property-group summary::-webkit-details-marker {
  display: none;
}

.view-group summary::after,
.property-group summary::after {
  content: "";
  width: 7px;
  height: 7px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  transition: transform 120ms ease;
}

.view-group[open] summary::after,
.property-group[open] summary::after {
  transform: rotate(225deg);
}

.view-group .view-list,
.property-group .field-grid,
.property-group .compact-review {
  margin-top: 8px;
}

.utility-group .sidebar-stats,
.utility-group .mailbox-card {
  margin-top: 8px;
}

.view-list {
  display: grid;
  gap: 4px;
}

.view-button {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  width: 100%;
  border: 0;
  border-radius: 7px;
  padding: 9px 10px;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.view-button:hover,
.view-button.active {
  background: var(--surface-hover);
}

.view-button.active strong {
  color: var(--primary);
}

.view-button.active .count {
  background: rgba(37, 99, 235, 0.12);
  color: var(--primary);
}

.view-button small {
  display: none;
}

.count {
  display: inline-flex;
  justify-content: center;
  min-width: 28px;
  border-radius: 999px;
  padding: 2px 8px;
  background: #e8edf2;
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
}

.mailbox-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--surface-soft);
}

.mailbox-card strong {
  display: block;
  margin-top: 4px;
  font-size: 13px;
}

.mailbox-card p {
  display: none;
}

.sidebar-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  overflow: hidden;
  border: 0;
  border-radius: 8px;
  background: var(--surface-soft);
}

.sidebar-stats div {
  display: grid;
  gap: 2px;
  padding: 8px 6px;
  text-align: center;
}

.sidebar-stats div + div {
  border-left: 1px solid var(--line);
}

.sidebar-stats span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.sidebar-stats strong {
  font-size: 16px;
}

.workspace {
  min-width: 0;
  padding: 18px;
  overflow: hidden;
}

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

.topbar h2 {
  margin-top: 2px;
  font-size: 26px;
  line-height: 1.15;
}

.topbar-actions {
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

.search-field input {
  width: min(320px, 38vw);
}

.search-field,
.toolbar-controls label,
.field-grid label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  outline: none;
  transition:
    border-color 120ms ease,
    box-shadow 120ms ease,
    background 120ms ease;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: var(--focus);
}

input,
select {
  min-height: 38px;
  padding: 7px 10px;
}

textarea {
  resize: vertical;
  padding: 11px;
  line-height: 1.5;
}

.primary-button,
.secondary-button,
.ghost-button,
.macro-chip,
.icon-button {
  min-height: 38px;
  border-radius: 7px;
  padding: 7px 12px;
  border: 1px solid transparent;
  font-weight: 800;
  white-space: nowrap;
  transition:
    border-color 120ms ease,
    background 120ms ease,
    color 120ms ease,
    transform 120ms ease;
}

.primary-button {
  background: var(--primary);
  color: #ffffff;
}

.primary-button:hover {
  background: var(--primary-dark);
}

.secondary-button,
.macro-chip {
  border-color: var(--line-strong);
  background: #ffffff;
  color: var(--text);
}

.secondary-button:hover,
.macro-chip:hover,
.icon-button:hover {
  border-color: var(--primary);
}

.command-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.button-icon {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: var(--surface-hover);
  color: var(--primary);
  font-weight: 900;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 38px;
  padding: 0;
  border-color: var(--line-strong);
  background: #ffffff;
  color: var(--text);
}

.theme-icon {
  display: block;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.sun-icon {
  display: none;
}

:root[data-theme="dark"] .sun-icon {
  display: block;
}

:root[data-theme="dark"] .moon-icon {
  display: none;
}

.ghost-button {
  background: transparent;
  color: var(--muted);
}

.stats-row {
  display: none;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.stat-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.stat-card span,
.stat-card small {
  display: block;
  color: var(--muted);
}

.stat-card span {
  font-size: 13px;
  font-weight: 800;
}

.stat-card strong {
  display: block;
  margin: 5px 0 2px;
  font-size: 28px;
}

.main-grid {
  display: grid;
  grid-template-columns: minmax(360px, 430px) minmax(0, 1fr);
  gap: 14px;
  align-items: start;
  height: calc(100vh - 112px);
}

.ticket-list-panel,
.ticket-detail-panel,
.side-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.ticket-list-panel,
.ticket-detail-panel {
  overflow: hidden;
  min-height: 0;
  max-height: calc(100vh - 112px);
}

.list-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.list-toolbar h3 {
  margin-top: 4px;
  font-size: 18px;
}

.toolbar-controls {
  min-width: 142px;
}

.ticket-list {
  display: grid;
  max-height: calc(100vh - 180px);
  overflow: auto;
}

.ticket-row {
  display: grid;
  gap: 6px;
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: 13px 14px;
  background: transparent;
  color: inherit;
  text-align: left;
}

.ticket-row:hover,
.ticket-row.active {
  background: var(--surface-hover);
}

.ticket-row.active {
  box-shadow: inset 3px 0 0 var(--primary);
}

.ticket-row strong {
  font-size: 14px;
  line-height: 1.35;
}

.row-meta,
.row-tags,
.ticket-kicker,
.ticket-actions,
.reply-actions,
.reply-meta,
.macro-strip {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
}

.row-meta,
.reply-actions,
.reply-meta,
.message-meta,
.muted {
  color: var(--muted);
  font-size: 13px;
}

.row-tags {
  gap: 5px;
}

.ticket-row .tag {
  color: var(--muted);
}

.ticket-row:not(.active) .tag,
.ticket-row:not(.active) .review-pill,
.ticket-row:not(.active) .priority-pill {
  display: none;
}

.pill,
.tag,
.status-pill,
.priority-pill,
.review-pill {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 800;
}

.pill,
.tag {
  border: 1px solid var(--line);
  background: #ffffff;
}

.status-new,
.status-open {
  background: #eaf4ff;
  color: var(--blue);
}

.status-pending,
.status-waiting-customer {
  background: #fff6df;
  color: var(--amber);
}

.status-on-hold {
  background: #e8edf2;
  color: #3c4650;
}

.status-solved,
.status-closed {
  background: #e9f8ef;
  color: var(--green);
}

.priority-critical,
.review-bad {
  background: #ffe9ea;
  color: var(--red);
}

.priority-high {
  background: #fff0dd;
  color: var(--amber);
}

.priority-normal {
  background: #eaf4ff;
  color: var(--blue);
}

.priority-low,
.review-good {
  background: #e9f8ef;
  color: var(--green);
}

.ticket-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 17px 18px;
  border-bottom: 1px solid var(--line);
}

.ticket-header h3 {
  margin-top: 6px;
  font-size: 22px;
  line-height: 1.25;
}

.ticket-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  min-height: 0;
  max-height: calc(100vh - 196px);
  overflow: hidden;
}

.conversation-column {
  min-width: 0;
  overflow-y: auto;
  border-right: 1px solid var(--line);
}

.properties-panel {
  min-width: 0;
  overflow-y: auto;
  background: color-mix(in srgb, var(--surface-soft) 92%, var(--surface));
}

.properties-title {
  display: none;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  padding: 0 16px 14px;
  border-bottom: 1px solid var(--line);
}

.macro-strip {
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 8px 16px 0;
  border-bottom: 1px solid var(--line);
}

.tab {
  border: 0;
  border-bottom: 3px solid transparent;
  padding: 9px 10px;
  background: transparent;
  color: var(--muted);
  font-weight: 900;
}

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

.tab-panel {
  display: none;
  padding: 16px;
}

.guide-inline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: 14px 16px 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: linear-gradient(180deg, var(--surface-soft), var(--surface));
}

.guide-inline strong {
  display: block;
  margin-top: 3px;
}

.guide-inline p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.tab-panel.active {
  display: block;
}

.message-stream {
  display: grid;
  gap: 10px;
}

.message {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #ffffff;
}

.message.customer {
  border-left: 4px solid var(--blue);
}

.message.agent {
  border-left: 4px solid var(--primary);
}

.message.internal,
.message.audit {
  border-left: 4px solid #7a8794;
}

.message p {
  margin: 8px 0 0;
  line-height: 1.5;
}

.message-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.reply-box {
  display: grid;
  gap: 11px;
  margin: 0;
  padding: 14px 16px 16px;
  border-top: 1px solid var(--line);
}

.reply-meta {
  justify-content: space-between;
}

.reply-actions {
  justify-content: space-between;
  gap: 8px;
}

.reply-actions select {
  width: auto;
  min-width: 160px;
}

.composer-mode {
  display: inline-flex;
  width: fit-content;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
}

.mode-button {
  min-height: 34px;
  border: 0;
  padding: 7px 11px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.mode-button.active {
  background: var(--surface-hover);
  color: var(--text);
}

.guide-panel,
.review-panel,
.customer-panel,
.compact-list {
  display: grid;
  gap: 10px;
}

.compact-review {
  padding: 0 16px 14px;
}

.property-group {
  border-bottom: 1px solid var(--line);
  padding-top: 14px;
}

.property-group summary {
  padding: 0 16px;
}

.property-group:last-child {
  border-bottom: 0;
}

.guide-card,
.review-card,
.customer-item,
.compact-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface-soft);
}

.guide-card h4,
.review-card h4 {
  margin: 0 0 6px;
}

.guide-card p,
.review-card p,
.customer-item p,
.compact-item p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.guide-steps {
  margin: 10px 0;
  padding-left: 18px;
  font-size: 13px;
  line-height: 1.45;
}

.guide-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.audit-stream {
  max-height: calc(100vh - 420px);
  overflow: auto;
}

.side-panel {
  display: none;
  gap: 16px;
}

.side-card {
  padding: 14px;
}

.side-card-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.side-card-header span {
  color: var(--muted);
  font-size: 12px;
}

.weekly-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.weekly-grid div {
  display: grid;
  gap: 4px;
  padding: 12px;
  text-align: center;
}

.weekly-grid div + div {
  border-left: 1px solid var(--line);
}

.weekly-grid strong {
  color: var(--blue);
  font-size: 22px;
}

.weekly-grid span {
  color: var(--muted);
  font-size: 12px;
}

.empty-state {
  padding: 26px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 1400px) {
  .main-grid {
    grid-template-columns: minmax(340px, 410px) minmax(0, 1fr);
  }

  .side-panel {
    display: none;
  }
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .rail {
    display: none;
  }

  .views {
    min-height: auto;
    padding: 16px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .view-section {
    border-top: 1px solid var(--line);
    padding-top: 12px;
  }

  .main-grid,
  .side-panel {
    grid-template-columns: 1fr;
  }

  .ticket-list,
  .audit-stream {
    max-height: none;
  }
}

@media (max-width: 720px) {
  .workspace {
    padding: 16px;
  }

  .topbar,
  .ticket-header,
  .list-toolbar {
    flex-direction: column;
  }

  .stats-row,
  .field-grid {
    grid-template-columns: 1fr;
  }

  .topbar-actions {
    display: grid;
    grid-template-columns: 1fr auto auto;
    width: 100%;
  }

  .search-field {
    grid-column: 1 / -1;
  }

  .search-field input {
    width: 100%;
  }

  .compact-command {
    justify-self: start;
  }
}
