:root {
  --orange: #E0400D;
  --orange-dark: #b52f07;
  --orange-soft: #fff0eb;
  --orange-soft-2: #ffe1d7;
  --bg: #fff6f1;
  --surface: #ffffff;
  --surface-2: #fffaf7;
  --text: #241815;
  --muted: #8c766f;
  --line: #f3d4c8;
  --shadow: 0 18px 50px rgba(224, 64, 13, 0.12);
  --green: #15803d;
  --red: #b91c1c;
  --yellow: #b45309;
  --radius-lg: 28px;
  --radius: 18px;
  --sidebar-width: 264px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 8% 6%, rgba(224, 64, 13, 0.18), transparent 25%),
    linear-gradient(135deg, #fff7f3 0%, #fff3ed 44%, #ffe1d5 100%);
}

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

button {
  cursor: pointer;
}

.sidebar {
  position: fixed;
  inset: 18px auto 18px 18px;
  width: var(--sidebar-width);
  padding: 18px;
  border: 1px solid rgba(224, 64, 13, 0.18);
  border-radius: 30px;
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 22px;
  z-index: 20;
}

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

.brand-icon {
  width: 48px;
  height: 48px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: var(--orange);
  color: white;
  font-weight: 900;
  font-size: 22px;
  box-shadow: 0 14px 30px rgba(224, 64, 13, 0.28);
}

.brand strong {
  display: block;
  font-size: 18px;
}

.brand span,
.connection-card span,
.connection-card small,
.muted {
  color: var(--muted);
}

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

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

.nav-link {
  text-decoration: none;
  color: var(--text);
  padding: 13px 14px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  border: 1px solid transparent;
  transition: 0.18s ease;
}

.nav-link span {
  width: 26px;
  height: 26px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: var(--orange-soft);
  color: var(--orange);
}

.nav-link:hover,
.nav-link.active {
  color: var(--orange);
  background: var(--orange-soft);
  border-color: var(--orange-soft-2);
}

.connection-card {
  margin-top: auto;
  padding: 16px;
  border-radius: 22px;
  background: linear-gradient(135deg, var(--orange-soft), #fff);
  border: 1px solid var(--line);
  display: grid;
  gap: 5px;
}

.connection-card strong {
  color: var(--green);
}

.main {
  margin-left: calc(var(--sidebar-width) + 44px);
  padding: 26px 28px 60px;
  max-width: 1500px;
}

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

.eyebrow,
.section-kicker {
  margin: 0 0 6px;
  color: var(--orange);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  font-size: 12px;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(28px, 5vw, 48px);
  letter-spacing: -0.05em;
  line-height: 0.95;
}

.compact-page-title .topbar h1 {
  display: none;
}

.topbar-pill {
  padding: 10px 14px;
  border-radius: 999px;
  background: var(--orange);
  color: white;
  font-size: 12px;
  font-weight: 900;
  box-shadow: 0 12px 32px rgba(224, 64, 13, 0.22);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.hero-card,
.machine-hero,
.panel,
.client-form-card,
.detail-card {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(224, 64, 13, 0.16);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.hero-card,
.machine-hero {
  padding: 24px;
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  background:
    linear-gradient(135deg, rgba(224, 64, 13, 0.12), rgba(255, 255, 255, 0.92)),
    white;
}

.hero-card h2,
.machine-hero h2,
.panel-header h2,
.form-title-row h2,
.detail-head h2 {
  margin: 0;
  letter-spacing: -0.04em;
}

.hero-card p:last-child,
.machine-hero p:last-child,
.panel-header p,
.form-block-title p,
.form-title-row p:last-child {
  margin: 6px 0 0;
  color: var(--muted);
}

.hero-spark {
  width: 74px;
  height: 74px;
  border-radius: 24px;
  display: grid;
  place-items: center;
  background: var(--orange);
  color: white;
  font-size: 34px;
  box-shadow: 0 18px 50px rgba(224, 64, 13, 0.28);
}

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

.metric-card {
  padding: 20px;
  border-radius: 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: 0 10px 28px rgba(224, 64, 13, 0.08);
  min-height: 138px;
  display: grid;
  align-content: space-between;
}

.metric-card span,
.metric-card small {
  color: var(--muted);
  font-weight: 700;
}

.metric-card strong {
  display: block;
  font-size: clamp(26px, 4vw, 38px);
  letter-spacing: -0.05em;
  margin: 8px 0;
}

.metric-card.highlight {
  color: white;
  background: linear-gradient(135deg, var(--orange), #ff784d);
  border-color: transparent;
}

.metric-card.highlight span,
.metric-card.highlight small {
  color: rgba(255, 255, 255, 0.84);
}

.metric-card.orange-soft {
  background: linear-gradient(135deg, #fff, var(--orange-soft));
}

.metric-card.danger-soft {
  background: linear-gradient(135deg, #fff, #fff0f0);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(320px, 0.8fr);
  gap: 18px;
}

.panel {
  padding: 22px;
}

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

.panel-header h2 {
  font-size: 24px;
}

.due-list {
  display: grid;
  gap: 10px;
}

.due-item {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 18px;
  padding: 14px;
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 12px;
  color: inherit;
}

.due-item strong,
.due-item small {
  display: block;
}

.due-item small {
  color: var(--muted);
}

.status-summary {
  display: grid;
  gap: 12px;
}

.status-summary div {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface-2);
}

.status-summary p {
  margin: 0;
  color: var(--muted);
  font-weight: 800;
}

.status-summary strong {
  font-size: 22px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--orange);
}

.dot.ok { background: var(--green); }
.dot.warning { background: var(--yellow); }
.dot.danger { background: var(--red); }

.clients-panel {
  overflow: hidden;
}

.client-header,
.machine-hero {
  align-items: center;
}

.compact-title h2 {
  font-size: 26px;
}

.primary-button,
.secondary-button,
.ghost-button,
.row-actions button {
  border: 0;
  border-radius: 14px;
  padding: 12px 16px;
  font-weight: 900;
  transition: 0.18s ease;
}

.primary-button {
  background: var(--orange);
  color: white;
  box-shadow: 0 12px 28px rgba(224, 64, 13, 0.2);
}

.primary-button:hover {
  background: var(--orange-dark);
  transform: translateY(-1px);
}

.secondary-button {
  color: var(--orange);
  background: var(--orange-soft);
  border: 1px solid var(--orange-soft-2);
}

.ghost-button,
.row-actions button {
  color: var(--orange);
  background: white;
  border: 1px solid var(--line);
}

.list-tools {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) 220px;
  gap: 12px;
  margin-bottom: 16px;
}

label,
.full-label {
  display: grid;
  gap: 7px;
  color: #63483f;
  font-weight: 900;
  font-size: 14px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px 15px;
  background: white;
  color: var(--text);
  outline: none;
  transition: 0.18s ease;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--orange);
  box-shadow: 0 0 0 4px rgba(224, 64, 13, 0.12);
}

textarea {
  resize: vertical;
}

.table-wrap {
  overflow-x: auto;
  border-radius: 22px;
  border: 1px solid var(--line);
}

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

th,
td {
  text-align: left;
  padding: 14px 15px;
  border-bottom: 1px solid #f6ded6;
  vertical-align: middle;
}

th {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  background: var(--orange-soft);
}

tbody tr:hover {
  background: #fffaf8;
}

.client-main {
  display: grid;
  gap: 3px;
}

.client-main small {
  color: var(--muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.badge.ok,
.badge.active,
.badge.available {
  background: #e8f7ed;
  color: var(--green);
}

.badge.pending,
.badge.paused,
.badge.rented {
  background: #fff7e6;
  color: var(--yellow);
}

.badge.late,
.badge.closed,
.badge.maintenance {
  background: #fff0f0;
  color: var(--red);
}

.badge.free {
  background: #eef2ff;
  color: #3730a3;
}

.empty-cell,
.empty-state {
  color: var(--muted);
  text-align: center;
  padding: 28px;
  font-weight: 700;
}

.row-actions {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
}

.row-actions button {
  padding: 9px 11px;
  border-radius: 12px;
}

.client-form-card,
.detail-shell {
  max-width: 1160px;
}

.client-form-card {
  padding: 22px;
}

.form-title-row,
.detail-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 18px;
}

.form-actions-top,
.form-footer-actions,
.inline-actions,
.machine-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.form-block {
  position: relative;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.82);
  margin-bottom: 14px;
}

.orange-line::before {
  content: '';
  position: absolute;
  inset: 18px auto 18px 0;
  width: 4px;
  border-radius: 999px;
  background: var(--orange);
}

.form-block-title {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}

.form-block-title span {
  width: 36px;
  height: 36px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  background: var(--orange);
  color: white;
  font-weight: 900;
  flex: 0 0 auto;
}

.form-block-title h3 {
  margin: 0;
  font-size: 18px;
}

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

.compact-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.full-label {
  width: 100%;
}

.form-footer-actions {
  justify-content: flex-end;
  margin-top: 16px;
}

.form-error {
  color: var(--red);
  font-weight: 800;
  margin: 10px 0 0;
}

.detail-shell {
  display: grid;
  gap: 16px;
}

.detail-card {
  padding: 24px;
}

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

.detail-head h2 {
  font-size: clamp(28px, 4vw, 42px);
}

.detail-head p {
  margin: 6px 0 0;
  color: var(--muted);
}

.detail-badges {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

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

.detail-section {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--surface-2);
}

.detail-section-wide {
  grid-column: 1 / -1;
}

.detail-section h3 {
  margin: 0 0 12px;
  color: var(--orange);
}

.detail-item {
  display: grid;
  grid-template-columns: minmax(120px, 0.6fr) minmax(0, 1fr);
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px dashed rgba(224, 64, 13, 0.2);
}

.detail-item:last-child {
  border-bottom: 0;
}

.detail-item span {
  color: var(--muted);
  font-weight: 800;
}

.detail-item strong {
  min-width: 0;
  overflow-wrap: anywhere;
}

.detail-note {
  margin: 0;
  color: #5e463d;
  line-height: 1.65;
  white-space: pre-wrap;
}

.machine-metrics {
  margin-top: 0;
}

.maintenance-panel.hidden {
  display: none;
}

.maintenance-form {
  display: grid;
  grid-template-columns: minmax(180px, 0.8fr) minmax(160px, 0.6fr) minmax(260px, 1.4fr) auto;
  gap: 12px;
  align-items: end;
}

.maintenance-description {
  grid-column: span 1;
}

.history-panel {
  box-shadow: var(--shadow);
}

.history-list {
  display: grid;
  gap: 12px;
}

.history-item {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface-2);
  display: grid;
  gap: 10px;
}

.history-item strong,
.history-item small {
  display: block;
}

.history-item small {
  color: var(--muted);
}

.history-item p {
  margin: 0;
  line-height: 1.55;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100vw - 36px));
  background: #241815;
  color: white;
  padding: 14px 16px;
  border-radius: 18px;
  box-shadow: 0 18px 50px rgba(36, 24, 21, 0.24);
  transform: translateY(24px);
  opacity: 0;
  pointer-events: none;
  transition: 0.2s ease;
  z-index: 40;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

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

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

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

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

  .maintenance-description,
  .maintenance-form .inline-actions,
  .maintenance-form .form-error {
    grid-column: 1 / -1;
  }
}

@media (max-width: 860px) {
  body {
    padding-bottom: calc(86px + env(safe-area-inset-bottom));
  }

  .sidebar {
    inset: auto 10px calc(10px + env(safe-area-inset-bottom)) 10px;
    width: auto;
    min-height: 68px;
    border-radius: 24px;
    padding: 10px;
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
    gap: 10px;
  }

  .brand {
    padding: 0 0 0 4px;
  }

  .brand-icon {
    width: 42px;
    height: 42px;
    border-radius: 14px;
  }

  .brand strong,
  .brand span,
  .connection-card {
    display: none;
  }

  .nav {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  .nav-link {
    justify-content: center;
    padding: 10px 8px;
    font-size: 12px;
    border-radius: 16px;
    gap: 5px;
  }

  .nav-link span {
    width: 22px;
    height: 22px;
    border-radius: 9px;
  }

  .main {
    margin-left: 0;
    padding: 18px 12px 32px;
  }

  .topbar {
    margin-bottom: 14px;
    align-items: flex-start;
  }

  .topbar h1 {
    font-size: 34px;
  }

  .topbar-pill {
    display: none;
  }

  .hero-card,
  .machine-hero,
  .panel,
  .client-form-card,
  .detail-card {
    border-radius: 22px;
  }

  .hero-card,
  .machine-hero,
  .panel,
  .client-form-card,
  .detail-card {
    padding: 16px;
  }

  .hero-spark {
    width: 52px;
    height: 52px;
    border-radius: 18px;
    font-size: 24px;
  }

  .metrics-grid {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .metric-card {
    min-height: 118px;
    padding: 15px;
    border-radius: 20px;
  }

  .metric-card strong {
    font-size: 26px;
  }

  .panel-header,
  .client-header,
  .machine-hero,
  .form-title-row,
  .detail-head,
  .detail-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .primary-button,
  .secondary-button,
  .ghost-button {
    width: 100%;
    justify-content: center;
  }

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

  .table-wrap {
    border: 0;
    overflow: visible;
  }

  .responsive-table,
  .responsive-table thead,
  .responsive-table tbody,
  .responsive-table tr,
  .responsive-table td {
    display: block;
    width: 100%;
  }

  .responsive-table thead {
    display: none;
  }

  .responsive-table tr {
    margin-bottom: 12px;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: white;
    overflow: hidden;
    box-shadow: 0 10px 26px rgba(224, 64, 13, 0.08);
  }

  .responsive-table td {
    display: grid;
    grid-template-columns: minmax(92px, 0.4fr) minmax(0, 1fr);
    gap: 10px;
    padding: 12px 14px;
    border-bottom: 1px solid #f6ded6;
  }

  .responsive-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 900;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }

  .responsive-table td:last-child {
    border-bottom: 0;
  }

  .row-actions {
    justify-content: flex-start;
  }

  .row-actions button {
    flex: 1 1 auto;
  }

  .form-grid,
  .compact-grid,
  .detail-grid,
  .maintenance-form {
    grid-template-columns: 1fr;
  }

  .detail-section-wide {
    grid-column: auto;
  }

  .detail-item {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .due-item {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .form-actions-top,
  .form-footer-actions,
  .inline-actions,
  .machine-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .main {
    padding-left: 10px;
    padding-right: 10px;
  }

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

  .hero-card {
    align-items: flex-start;
  }

  .hero-spark {
    display: none;
  }

  .panel-header h2,
  .compact-title h2 {
    font-size: 22px;
  }

  .form-block {
    padding: 16px;
    border-radius: 20px;
  }

  input,
  select,
  textarea {
    font-size: 16px;
  }
}
