:root {
  --ink: #172126;
  --muted: #61717a;
  --line: #d9e3e3;
  --bg: #f4f7f6;
  --panel: #ffffff;
  --brand: #155e63;
  --brand-strong: #0e4448;
  --accent: #c76f21;
  --ok: #157347;
  --warn: #b45309;
  --danger: #b42318;
  --info: #2f5f9f;
  --shadow: 0 18px 45px rgba(27, 48, 54, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

body {
  margin: 0;
  min-height: 100%;
}

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

button {
  cursor: pointer;
}

.auth-gate {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
  background: #edf4f3;
}

.auth-card {
  width: min(430px, 100%);
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.auth-card h1 {
  margin: 0 0 8px;
  font-size: 1.7rem;
  letter-spacing: 0;
}

.auth-card p {
  color: var(--muted);
}

.google-signin-button {
  min-height: 44px;
  margin-top: 18px;
}

.auth-status {
  min-height: 20px;
  margin: 14px 0 0;
  color: var(--danger);
  font-size: 0.9rem;
  font-weight: 750;
}

.app-shell {
  width: min(1440px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 22px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 20px;
  background: #113f43;
  color: #f8fbfb;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.topbar h1,
.panel h2,
.panel h3,
.metric strong {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: clamp(1.55rem, 2vw, 2.3rem);
  line-height: 1.05;
}

.data-source {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin: 9px 0 0;
  padding: 5px 9px;
  border: 1px solid rgba(235, 244, 244, 0.28);
  border-radius: 6px;
  color: #d8e8e8;
  font-size: 0.76rem;
  font-weight: 700;
}

.data-source.is-live {
  border-color: rgba(151, 231, 188, 0.42);
  color: #c6f2d8;
}

.data-source-label {
  margin-right: 4px;
}

.data-source .source-link {
  padding: 4px 8px;
  border: 1px solid rgba(198, 242, 216, 0.34);
  border-radius: 5px;
  background: rgba(198, 242, 216, 0.1);
  color: #f0fbf4;
  text-decoration: none;
}

.data-source .source-link:hover {
  border-color: rgba(198, 242, 216, 0.7);
  background: rgba(198, 242, 216, 0.2);
}

.data-source .source-link:focus-visible {
  outline: 2px solid #f0fbf4;
  outline-offset: 2px;
}

.eyebrow {
  margin: 0 0 5px;
  color: inherit;
  opacity: 0.72;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.user-switcher {
  display: grid;
  gap: 6px;
  min-width: min(260px, 45vw);
}

.user-switcher label {
  color: #d8e8e8;
  font-size: 0.78rem;
  font-weight: 700;
}

.authenticated-user {
  min-height: 40px;
  padding: 9px 11px;
  border: 1px solid rgba(235, 244, 244, 0.28);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  color: #f8fbfb;
  font-size: 0.9rem;
  font-weight: 800;
}

.header-button {
  min-height: 36px;
  border: 1px solid rgba(235, 244, 244, 0.35);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.1);
  color: #f8fbfb;
  font-weight: 850;
}

.header-button:hover {
  background: rgba(255, 255, 255, 0.18);
}

.tabs {
  display: flex;
  gap: 8px;
  margin: 18px 0;
  padding: 5px;
  background: #dfe9e8;
  border: 1px solid var(--line);
  border-radius: 8px;
  width: fit-content;
}

.tab {
  min-height: 38px;
  padding: 0 16px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.tab.is-active {
  background: var(--panel);
  color: var(--brand-strong);
  box-shadow: 0 8px 18px rgba(15, 63, 67, 0.12);
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

.compact-form {
  margin: 10px 0 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.rune-import {
  display: grid;
  gap: 9px;
  margin-bottom: 18px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.admin-import-tools {
  padding: 12px;
  margin-bottom: 14px;
  border: 1px solid #d7e8e7;
  border-radius: 8px;
  background: #f5faf9;
}

.admin-import-tools[hidden] {
  display: none;
}

.section-head h3 {
  font-size: 0.95rem;
}

.subsection-head {
  margin-top: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.full-button {
  width: 100%;
}

.import-summary {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

.import-results {
  display: grid;
  gap: 8px;
  max-height: 265px;
  overflow: auto;
}

.import-item {
  display: grid;
  gap: 7px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.import-item strong,
.import-item span {
  display: block;
  font-size: 0.78rem;
}

.import-item span,
.import-item p {
  color: var(--muted);
}

.import-pdf-label {
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.reference-tag {
  color: var(--brand-strong);
  font-weight: 800;
}

.work-address {
  margin: 7px 0 0;
  color: var(--ink);
  font-size: 0.94rem;
  font-weight: 750;
  line-height: 1.35;
}

a.work-address {
  display: inline-block;
  color: var(--brand-strong);
  text-decoration: underline;
  text-underline-offset: 3px;
}

a.work-address:hover {
  color: var(--brand);
}

.customer-name {
  margin: 7px 0 0;
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 700;
}

.contact-link,
.contact-missing {
  display: inline-block;
  margin: 6px 0 0;
  color: var(--brand-strong);
  font-size: 0.86rem;
  font-weight: 700;
}

.contact-missing {
  color: var(--muted);
  font-weight: 600;
}

.network-code {
  margin: 6px 0 0;
  color: var(--brand-strong);
  font-size: 0.82rem;
  font-weight: 700;
}

.order-deadline {
  display: inline-flex;
  margin: 8px 0 0;
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 0.78rem;
  font-weight: 800;
}

.deadline-active {
  background: #e8f4ef;
  color: #176743;
}

.deadline-warning {
  background: #fff3db;
  color: #8e5b05;
}

.deadline-overdue {
  background: #fde7e5;
  color: #ad2e27;
}

.deadline-neutral {
  background: #eef3f3;
  color: var(--muted);
}

.work-description {
  white-space: pre-wrap;
}

.import-item p {
  margin: 5px 0 0;
  font-size: 0.8rem;
  line-height: 1.35;
}

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

.metric {
  min-height: 104px;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 24px rgba(27, 48, 54, 0.08);
}

.metric span {
  display: block;
  color: var(--muted);
  font-weight: 800;
  font-size: 0.76rem;
  text-transform: uppercase;
}

.metric strong {
  display: block;
  margin-top: 9px;
  font-size: 2rem;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 14px;
  align-items: start;
}

.technician-grid {
  grid-template-columns: minmax(320px, 0.75fr) minmax(360px, 1fr);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 24px rgba(27, 48, 54, 0.08);
  padding: 18px;
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.panel h2 {
  font-size: 1.28rem;
}

.panel h3 {
  margin-bottom: 10px;
  font-size: 1rem;
}

.toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
}

.input {
  min-height: 40px;
  width: 100%;
  border: 1px solid #cbd8d8;
  border-radius: 6px;
  background: #fbfdfd;
  color: var(--ink);
  padding: 9px 11px;
  outline: none;
}

.input.order-search {
  width: min(330px, 100%);
}

.input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(21, 94, 99, 0.14);
}

.small-input {
  max-width: 190px;
}

.form-stack,
.completion-form {
  display: grid;
  gap: 12px;
}

.form-actions,
.client-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.form-actions button {
  flex: 1 1 140px;
}

.material-entry-list {
  display: grid;
  gap: 9px;
  margin-top: 10px;
}

.material-heading {
  margin-top: 14px;
}

.materials-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.additional-heading {
  margin-top: 20px;
}

.material-entry {
  display: grid;
  grid-template-columns: minmax(200px, 1fr) minmax(140px, 0.42fr) auto;
  align-items: end;
  gap: 8px;
}

.material-remove-button {
  padding: 0 10px;
}

.material-actions {
  display: flex;
  justify-content: flex-start;
  margin-top: 10px;
}

.form-stack label,
.completion-form label,
.field-label {
  display: grid;
  gap: 6px;
  color: #42535b;
  font-size: 0.86rem;
  font-weight: 800;
}

.submit-section {
  display: grid;
  gap: 12px;
}

.submit-button {
  min-height: 48px;
  width: 100%;
}

.primary-button,
.secondary-button,
.ghost-button {
  min-height: 40px;
  border-radius: 6px;
  border: 1px solid transparent;
  padding: 0 14px;
  font-weight: 850;
  white-space: nowrap;
}

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.primary-button {
  background: var(--brand);
  color: white;
}

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

.secondary-button {
  background: #fff5ea;
  border-color: #efcfaa;
  color: #7c3c08;
}

.danger-button {
  min-height: 40px;
  border: 1px solid #e6b7b3;
  border-radius: 6px;
  padding: 0 14px;
  background: #fff0ef;
  color: var(--danger);
  font-weight: 850;
}

.danger-button:hover {
  background: #fde3e1;
}

.ghost-button {
  background: #eef4f4;
  border-color: #d7e3e3;
  color: var(--brand-strong);
}

.orders-list,
.directory-list {
  display: grid;
  gap: 10px;
}

.intervention-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.interventions-table-wrap {
  margin-top: 14px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.interventions-table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.interventions-table th,
.interventions-table td {
  max-width: 280px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  white-space: normal;
  overflow-wrap: anywhere;
}

.interventions-table th {
  position: sticky;
  top: 0;
  background: #eaf3f3;
  color: var(--brand-strong);
  font-weight: 850;
}

.interventions-table tbody tr:last-child td {
  border-bottom: 0;
}

.table-link {
  color: var(--brand);
  font-weight: 800;
}

.order-card {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfd;
}

.order-card:hover {
  border-color: #a8c8ca;
}

.order-main {
  display: grid;
  gap: 8px;
}

.order-title-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
}

.order-title-row h3 {
  margin: 0;
  font-size: 1.02rem;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.order-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 0.86rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  max-width: 100%;
  padding: 4px 8px;
  border-radius: 999px;
  background: #edf3f3;
  color: #355056;
  font-size: 0.78rem;
  font-weight: 850;
  overflow-wrap: anywhere;
}

.chip.status-novi {
  background: #edf2f7;
  color: #344054;
}

.chip.status-otvoren {
  background: #fff6e6;
  color: var(--warn);
}

.chip.status-dodijeljen {
  background: #eef6ff;
  color: var(--info);
}

.chip.status-na-putu,
.chip.status-u-tijeku {
  background: #fff6e6;
  color: var(--warn);
}

.chip.status-zavrsen {
  background: #e8f6ed;
  color: var(--ok);
}

.chip.sync-ready {
  background: #edf8f2;
  color: var(--ok);
}

.chip.status-otkazan {
  background: #fdecec;
  color: var(--danger);
}

.chip.priority-hitno {
  background: #ffefea;
  color: var(--danger);
}

.order-actions,
.status-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.detail-head {
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
}

.detail-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.detail-title h2 {
  overflow-wrap: anywhere;
}

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

.detail-section p {
  margin: 0;
  color: #3a4b52;
  line-height: 1.5;
}

.office-sketch-panel {
  padding: 14px;
  border: 1px solid #d7e8e7;
  border-radius: 8px;
  background: #f5faf9;
}

.office-edit-panel,
.office-transfer-panel {
  padding: 14px;
  border: 1px solid #d7e8e7;
  border-radius: 8px;
  background: #f5faf9;
}

.office-delete-panel {
  display: flex;
  justify-content: flex-end;
}

.edit-fields-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.transfer-form {
  display: flex;
  gap: 10px;
  align-items: end;
  margin-top: 10px;
}

.transfer-form .input {
  flex: 1 1 auto;
}

.office-sketch-panel.detail-section {
  margin-top: 14px;
}

.note-list,
.history-list,
.image-list {
  display: grid;
  gap: 9px;
  margin-top: 10px;
}

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

.note-actions .secondary-button {
  min-width: 170px;
}

.note-item,
.history-item,
.client-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px;
  background: #fbfdfd;
}

.note-item p,
.client-item p {
  margin: 4px 0 0;
  color: var(--muted);
}

.client-actions {
  margin-top: 10px;
}

.history-item {
  color: var(--muted);
  font-size: 0.86rem;
}

.image-list {
  grid-template-columns: repeat(auto-fill, minmax(128px, 1fr));
}

.image-item {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: white;
}

.pdf-item {
  display: grid;
  gap: 8px;
  min-height: 112px;
  padding: 12px;
  border: 1px solid #e6d2c2;
  border-radius: 8px;
  background: #fff8f2;
  color: var(--accent);
  text-decoration: none;
}

.pdf-item strong {
  font-size: 1.18rem;
}

.pdf-item span {
  color: #664636;
  font-size: 0.82rem;
  overflow-wrap: anywhere;
}

.image-item img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
}

.image-item figcaption {
  padding: 8px;
  color: var(--muted);
  font-size: 0.78rem;
  overflow-wrap: anywhere;
}

.directory-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
}

.month-filter {
  display: grid;
  gap: 5px;
  color: #42535b;
  font-size: 0.8rem;
  font-weight: 800;
}

.report-controls {
  display: flex;
  gap: 8px;
  align-items: end;
}

.technician-stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 10px;
  margin-bottom: 22px;
}

.performance-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.performance-panel {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfd;
}

.leaderboard,
.work-mix {
  display: grid;
  gap: 7px;
}

.leader-row,
.mix-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 10px;
  min-height: 38px;
  padding: 7px 9px;
  border-radius: 6px;
  background: #eef4f4;
  font-size: 0.82rem;
}

.leader-row span,
.mix-row span {
  color: var(--muted);
}

.mix-row {
  grid-template-columns: minmax(0, 1fr) auto;
}

.leading-work {
  margin-top: 4px;
}

.compact-empty {
  min-height: 74px;
  font-size: 0.85rem;
}

.danger-zone {
  display: grid;
  gap: 10px;
  margin-top: 20px;
  padding: 14px;
  border: 1px solid #e6b7b3;
  border-radius: 8px;
  background: #fff8f7;
}

.danger-zone[hidden] {
  display: none;
}

.danger-zone p:not(.eyebrow) {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.45;
}

.chat-panel {
  max-width: 920px;
  margin: 0 auto;
}

.chat-messages {
  display: grid;
  gap: 10px;
  min-height: 360px;
  max-height: min(58vh, 640px);
  overflow: auto;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7faf9;
}

.chat-message {
  display: flex;
}

.chat-message.is-mine {
  justify-content: flex-end;
}

.chat-bubble {
  max-width: min(620px, 92%);
  padding: 10px 12px;
  border: 1px solid #d7e8e7;
  border-radius: 8px;
  background: white;
}

.chat-message.is-mine .chat-bubble {
  border-color: #b7d8d6;
  background: #eaf6f5;
}

.chat-meta {
  display: flex;
  gap: 10px;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
  font-size: 0.78rem;
}

.chat-meta span {
  color: var(--muted);
  white-space: nowrap;
}

.chat-bubble p {
  margin: 0;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.chat-form {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.chat-form .primary-button {
  justify-self: end;
}

.technician-stat {
  display: grid;
  gap: 5px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfd;
}

.technician-stat span {
  color: var(--muted);
  font-size: 0.8rem;
  overflow-wrap: anywhere;
}

.stat-values {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.stat-values div {
  padding: 7px 4px;
  border-radius: 6px;
  background: #eef4f4;
  text-align: center;
}

.stat-values b,
.stat-values small {
  display: block;
}

.stat-values b {
  font-size: 1.15rem;
  color: var(--brand-strong);
}

.stat-values small {
  color: var(--muted);
  font-size: 0.7rem;
}

.empty-state,
.empty-detail {
  color: var(--muted);
  min-height: 180px;
  display: grid;
  place-items: center;
  text-align: center;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%) translateY(18px);
  min-width: min(460px, calc(100vw - 32px));
  max-width: calc(100vw - 32px);
  padding: 12px 14px;
  border-radius: 8px;
  background: #172126;
  color: white;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
  box-shadow: var(--shadow);
}

.toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 1060px) {
  .metrics-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .workspace-grid,
  .technician-grid {
    grid-template-columns: 1fr;
  }

  .toolbar {
    width: 100%;
    flex-wrap: wrap;
  }

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

@media (max-width: 720px) {
  .app-shell {
    padding: 12px;
  }

  .topbar,
  .panel-head,
  .order-title-row,
  .detail-title {
    flex-direction: column;
    align-items: stretch;
  }

  .report-controls {
    align-items: stretch;
    flex-direction: column;
  }

  .intervention-toolbar {
    flex-direction: column;
  }

  .topbar {
    padding: 16px;
  }

  .user-switcher {
    min-width: 100%;
  }

  .tabs {
    width: 100%;
    overflow-x: auto;
  }

  .tab {
    flex: 1 0 auto;
  }

  .metrics-grid,
  .directory-grid,
  .edit-fields-grid,
  .performance-grid,
  .materials-grid {
    grid-template-columns: 1fr;
  }

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

  .transfer-form {
    flex-direction: column;
    align-items: stretch;
  }

  .panel {
    padding: 14px;
  }

  .order-actions,
  .status-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .primary-button,
  .secondary-button,
  .ghost-button,
  .danger-button {
    width: 100%;
    white-space: normal;
  }
}
