:root {
  --ink: #18202a;
  --muted: #657386;
  --line: #d9e0e8;
  --surface: #ffffff;
  --soft: #f4f7fa;
  --brand: #ecb53f;
  --brand-2: #c98521;
  --danger: #b42318;
  --warning: #b45309;
  --ok: #15803d;
  --shadow: 0 12px 32px rgba(24, 32, 42, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: #eef3f7;
}

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

button {
  border: 0;
  cursor: pointer;
}

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 252px 1fr;
}

.sidebar {
  background: #102822;
  color: #eff6fb;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.brand {
  display: flex;
  align-items: flex-start;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.mark {
  width: 48px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  font-weight: 800;
  font-size: 15px;
  flex: 0 0 auto;
}

.brand-logo {
  width: 220px;
  height: auto;
  display: block;
  flex: 0 0 auto;
}

.sidebar-logo {
  width: 170px;
  padding: 7px;
  border-radius: 8px;
  background: #fff;
}

.brand-payoff {
  display: block;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0;
  line-height: 1.25;
}

.brand strong {
  display: block;
  line-height: 1.1;
}

.brand span,
.session small,
.hint {
  color: #a9b9c7;
}

.session small {
  display: block;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav button,
.ghost {
  min-height: 42px;
  border-radius: 8px;
  padding: 0 12px;
  color: inherit;
  background: transparent;
  text-align: left;
}

.nav button.active,
.nav button:hover,
.ghost:hover {
  background: rgba(255, 255, 255, 0.1);
}

.session {
  margin-top: auto;
  display: grid;
  gap: 10px;
}

.main {
  padding: 28px;
  min-width: 0;
}

.topbar,
.toolbar,
.row,
.split,
.machine-head,
.ticket-head {
  display: flex;
  align-items: center;
  gap: 14px;
}

.topbar {
  justify-content: space-between;
  margin-bottom: 22px;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 4px;
  font-size: 28px;
}

h2 {
  font-size: 20px;
}

h3 {
  font-size: 16px;
}

.muted {
  color: var(--muted);
}

.grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 16px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  box-shadow: var(--shadow);
}

.span-3 {
  grid-column: span 3;
}

.span-4 {
  grid-column: span 4;
}

.span-5 {
  grid-column: span 5;
}

.span-7 {
  grid-column: span 7;
}

.span-8 {
  grid-column: span 8;
}

.span-12 {
  grid-column: 1 / -1;
}

.stat strong {
  display: block;
  font-size: 30px;
}

.toolbar {
  justify-content: space-between;
  flex-wrap: wrap;
}

.filters {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.filterbar {
  align-items: end;
  margin-bottom: 14px;
}

.search-field {
  flex: 1 1 320px;
}

.field {
  display: grid;
  gap: 6px;
}

.field label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px 12px;
  color: var(--ink);
}

textarea {
  min-height: 96px;
  resize: vertical;
}

.button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 8px;
  padding: 0 14px;
  background: var(--brand);
  color: #18202a;
  font-weight: 700;
  white-space: nowrap;
}

.button:hover {
  background: var(--brand-2);
  color: #fff;
}

.button.secondary {
  background: #fff4d6;
  color: #6b4308;
}

.button.danger {
  background: #fee4e2;
  color: var(--danger);
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 12px 10px;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 800;
}

.badge.ok {
  background: #dcfce7;
  color: var(--ok);
}

.badge.warn {
  background: #fef3c7;
  color: var(--warning);
}

.badge.danger {
  background: #fee4e2;
  color: var(--danger);
}

.badge.info {
  background: #dbeafe;
  color: #1d4ed8;
}

.machine-list,
.ticket-list {
  display: grid;
  gap: 12px;
}

.clinic-overview {
  display: grid;
  gap: 8px;
}

.clinic-directory-tools {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.clinic-directory-tools .field {
  flex: 1;
  margin: 0;
}

.clinic-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.clinic-card.has-service { border-left: 4px solid var(--danger); }

.clinic-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 74px;
  padding: 12px 44px 12px 16px;
  cursor: pointer;
  list-style: none;
  position: relative;
}

.clinic-summary::-webkit-details-marker { display: none; }
.clinic-summary::after {
  content: "›";
  position: absolute;
  right: 17px;
  top: 50%;
  font-size: 26px;
  color: var(--muted);
  transform: translateY(-50%) rotate(90deg);
  transition: transform .15s ease;
}

.clinic-card[open] .clinic-summary { border-bottom: 1px solid var(--line); }
.clinic-card[open] .clinic-summary::after { transform: translateY(-50%) rotate(-90deg); }
.clinic-summary h2, .clinic-summary p { margin: 0; }
.clinic-summary p { margin-top: 4px; }
.clinic-card-body { padding: 16px; }

.clinic-card-head,
.clinic-tools,
.clinic-columns,
.mini-row {
  display: flex;
  gap: 14px;
}

.clinic-card-head {
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 14px;
}

.clinic-contacts {
  text-align: right;
  min-width: 210px;
}

.clinic-contacts span {
  display: block;
  overflow-wrap: anywhere;
}

.clinic-contacts .button {
  margin-top: 8px;
  min-height: 34px;
}

.clinic-tools {
  align-items: end;
  margin-bottom: 14px;
}

.clinic-contact-list {
  display: grid;
  gap: 8px;
  margin: 0 0 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.clinic-contact-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.clinic-contact-row > div:first-child {
  min-width: 0;
}

.clinic-contact-row span {
  display: block;
  overflow-wrap: anywhere;
}

.clinic-tools .field:first-child {
  flex: 1 1 360px;
}

.clinic-columns {
  align-items: stretch;
}

.clinic-columns > div {
  min-width: 0;
  flex: 1;
}

.clinic-columns h3 {
  margin-bottom: 8px;
}

.mini-list {
  display: grid;
  gap: 8px;
}

.mini-row {
  align-items: center;
  justify-content: space-between;
  min-height: 52px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--soft);
}

.mini-row > div {
  min-width: 0;
}

.mini-row strong,
.mini-row span {
  display: block;
  overflow-wrap: anywhere;
}

.mini-machine-link {
  width: 100%;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease, transform .15s ease;
}

.mini-machine-link:hover {
  border-color: var(--brand-2);
  background: #fff8e8;
  transform: translateY(-1px);
}

.mini-machine-link:focus-visible {
  outline: 3px solid rgba(201, 133, 33, .25);
  outline-offset: 2px;
}

.mini-row-action {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.mini-open-label {
  color: var(--brand-2);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.compact-empty {
  padding: 16px;
}

.machine-card,
.ticket-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fff;
}

.ticket-card.ticket-unread {
  border-left: 4px solid var(--brand);
  background: #fffdf6;
}

.ticket-preview {
  display: -webkit-box;
  margin: 10px 0 0;
  overflow: hidden;
  color: var(--muted);
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.ticket-summary-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
}

.text-button {
  padding: 4px 0;
  color: #795514;
  background: transparent;
  font-weight: 800;
}

.text-button:hover,
.text-button:focus-visible {
  color: var(--brand-2);
  text-decoration: underline;
}

.ticket-detail-grid {
  align-items: start;
}

.ticket-sidebar {
  position: sticky;
  top: 20px;
  display: grid;
  gap: 18px;
}

.vertical-actions {
  flex-direction: column;
  align-items: stretch;
}

.ticket-conversation {
  display: grid;
  gap: 10px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.ticket-message {
  max-width: min(760px, 92%);
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--soft);
}

.ticket-message.staff-message {
  justify-self: end;
  background: #fff7df;
  border-color: #f1d98b;
}

.ticket-message.clinic-message,
.ticket-message.original-message {
  justify-self: start;
}

.ticket-message-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 6px;
}

.ticket-message p {
  margin: 0;
}

.reply-attachments {
  display: grid;
  gap: 6px;
  margin-top: 10px;
}

.attachment-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: fit-content;
  max-width: 100%;
  color: #795514;
  font-size: 13px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.delivery-status {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-size: 12px;
}

.delivery-status.error {
  color: var(--danger);
}

.ticket-reply-form {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.ticket-reply-form label {
  font-weight: 700;
}

.ticket-reply-form textarea {
  width: 100%;
  resize: vertical;
}

.ticket-reply-form input[type="file"] {
  width: 100%;
  padding: 10px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.compact-actions {
  margin-top: 0;
}

.machine-card.is-clickable {
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.machine-card.is-clickable:hover,
.machine-card.is-clickable:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 10px 24px rgba(15, 31, 45, 0.12);
  outline: none;
  transform: translateY(-1px);
}

.machine-head,
.ticket-head {
  justify-content: space-between;
  align-items: flex-start;
}

.machine-info {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  min-width: 0;
}

.machine-photo {
  width: 126px;
  min-width: 126px;
  display: grid;
  gap: 8px;
}

.machine-photo img,
.photo-preview img {
  width: 100%;
  display: block;
  border-radius: 8px;
  object-fit: cover;
}

.machine-photo img {
  height: 94px;
  border: 1px solid var(--line);
}

.machine-photo span {
  height: 94px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  display: grid;
  place-items: center;
  padding: 10px;
  color: var(--muted);
  background: var(--soft);
  text-align: center;
  font-size: 13px;
}

.machine-photo .fallback-logo {
  object-fit: contain;
  padding: 14px;
  background: var(--soft);
  border: 1px dashed var(--line);
}

.machine-photo .button {
  min-height: 34px;
  padding: 0 10px;
}

.photo-preview {
  margin-bottom: 14px;
}

.photo-preview img {
  max-height: 280px;
  border: 1px solid var(--line);
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.documents {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.documents-head,
.document-item,
.document-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.documents-head {
  justify-content: space-between;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.documents-head span,
.document-item span {
  display: block;
}

.document-list {
  display: grid;
  gap: 8px;
}

.document-item {
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--soft);
}

.document-item > div:nth-child(2) {
  min-width: 0;
  flex: 1;
}

.document-item strong {
  display: block;
  overflow-wrap: anywhere;
}

.doc-icon {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: #12202b;
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 800;
  flex: 0 0 auto;
}

.document-actions {
  flex: 0 0 auto;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.document-actions .button {
  min-height: 34px;
}

.document-empty {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 12px;
  color: var(--muted);
  background: #fff;
}

.ai-response {
  margin-top: 12px;
  border-left: 4px solid var(--brand);
  border-radius: 8px;
  padding: 12px;
  background: #e8f2f1;
}

.ai-response p {
  margin: 6px 0 0;
}

.notification-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.qr {
  width: 132px;
  height: 132px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.qr img {
  width: 124px;
  height: 124px;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(rgba(8, 39, 34, 0.74), rgba(8, 39, 34, 0.74)),
    url("https://images.unsplash.com/photo-1581093458791-9d15482442f6?auto=format&fit=crop&w=1800&q=80") center/cover;
}

.public-assist {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #eef3f7;
}

.login-panel,
.public-card {
  width: min(100%, 440px);
  background: rgba(255, 255, 255, 0.96);
  border-radius: 8px;
  padding: 28px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.28);
}

.public-card {
  width: min(100%, 720px);
}

.public-machine {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  margin-bottom: 18px;
}

.otp-box {
  margin: 14px 0;
  padding: 12px;
  background: #e8f2f1;
  border: 1px solid #b7d7d3;
  border-radius: 8px;
  color: #0f5f58;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(12, 22, 32, 0.5);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 5;
}

.modal .panel {
  width: min(100%, 620px);
  max-height: calc(100vh - 40px);
  overflow: auto;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.empty {
  padding: 28px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  text-align: center;
  color: var(--muted);
}

.timeline {
  display: grid;
  gap: 12px;
  margin-top: 12px;
}

.timeline div {
  border-left: 3px solid var(--brand);
  padding: 2px 0 2px 12px;
}

.timeline strong,
.timeline span {
  display: block;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: 360px;
  background: #12202b;
  color: #fff;
  padding: 14px 16px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  z-index: 10;
}

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

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 3;
    padding: 16px;
  }

  .nav {
    grid-template-columns: repeat(2, 1fr);
  }

  .brand {
    gap: 6px;
  }

  .sidebar-logo {
    width: 150px;
  }

  .session {
    margin-top: 0;
  }

  .span-3,
  .span-4,
  .span-5,
  .span-7,
  .span-8 {
    grid-column: 1 / -1;
  }

  .grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .span-12 {
    grid-column: 1 / -1;
  }

  .ticket-sidebar {
    position: static;
  }
}

@media (max-width: 620px) {
  .main {
    padding: 18px;
  }

  .sidebar {
    gap: 14px;
  }

  .brand-payoff {
    font-size: 12px;
  }

  .grid {
    grid-template-columns: 1fr;
  }

  .span-3,
  .span-4,
  .span-5,
  .span-7,
  .span-8,
  .span-12 {
    grid-column: 1 / -1;
  }

  .topbar,
  .filterbar,
  .clinic-directory-tools,
  .clinic-summary,
  .clinic-card-head,
  .clinic-tools,
  .clinic-contact-row,
  .clinic-columns,
  .split,
  .machine-head,
  .machine-info,
  .public-machine,
  .ticket-head,
  .document-item,
  .document-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .ticket-summary-footer {
    align-items: stretch;
    flex-direction: column;
  }

  .nav {
    grid-template-columns: 1fr;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .button {
    width: 100%;
  }

  .machine-photo {
    width: 100%;
    min-width: 0;
  }

  .machine-photo img,
  .machine-photo span {
    height: 180px;
  }

  .machine-photo .fallback-logo {
    padding: 24px;
  }

  .stat strong {
    font-size: 26px;
  }

  .table-wrap {
    margin-inline: -4px;
  }
}
