:root {
  color-scheme: light;
  --bg: #f5f2ec;
  --panel: #ffffff;
  --panel-soft: #fbfaf6;
  --line: #e2ddd4;
  --text: #292624;
  --muted: #6f6960;
  --red: #d11418;
  --red-2: #b40f13;
  --green: #2f7d54;
  --amber: #af741d;
  --radius: 8px;
  --shadow: 0 14px 38px rgba(59, 42, 34, .10);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { max-width: 100%; overflow-x: hidden; }
body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(135deg, #fbfaf6 0%, #f4f0e8 52%, #ebe6dc 100%);
  color: var(--text);
}
button, input, textarea, select { font: inherit; }
button {
  min-height: 52px;
  border: 0;
  border-radius: var(--radius);
  color: var(--text);
  background: var(--panel-soft);
  padding: 0 18px;
  cursor: pointer;
  font-weight: 800;
}
button:hover { filter: brightness(.98); }
.primary { background: linear-gradient(135deg, var(--red), #a50e12); color: #fff; box-shadow: 0 10px 22px rgba(209,20,24,.18); }
.ghost { border: 1px solid var(--line); background: #fff; color: var(--text); }
.danger { background: #f8e8e9; color: #8a1723; border: 1px solid #edc9cd; }
.button-link {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  padding: 0 14px;
  text-decoration: none;
  font-weight: 800;
}
.hidden { display: none !important; }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(209,20,24,.08), transparent 48%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cpath d='M0 139h140M1 0v140' stroke='%23e7e1d7'/%3E%3C/svg%3E");
}
.login-panel {
  width: min(520px, 100%);
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255,255,255,.95);
  box-shadow: var(--shadow);
}
.brand-mark {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  background: var(--red);
  color: #fff;
  font-weight: 900;
}
.login-logo {
  width: min(460px, 100%);
  max-height: 150px;
  height: auto;
  object-fit: contain;
  object-position: left center;
  display: block;
  margin-bottom: 18px;
}
.brand-logo {
  width: min(236px, 100%);
  max-height: 84px;
  height: auto;
  object-fit: contain;
  object-position: left center;
  display: block;
  flex: 0 0 auto;
}
h1, h2, h3 { margin: 0; letter-spacing: 0; }
h1 { font-size: clamp(34px, 7vw, 56px); line-height: 1; margin: 16px 0; }
h2 { font-size: 28px; }
h3 { font-size: 18px; }
.eyebrow { margin: 0 0 8px; color: var(--red); text-transform: uppercase; font-size: 12px; font-weight: 900; letter-spacing: .08em; }
.muted { color: var(--muted); line-height: 1.55; }
.error { color: var(--red); min-height: 24px; }
.stack { display: grid; gap: 16px; }
label { display: grid; gap: 8px; color: var(--muted); font-size: 13px; font-weight: 800; min-width: 0; }
input, textarea, select {
  width: 100%;
  min-width: 0;
  min-height: 56px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 15px;
  background: #fff;
  color: var(--text);
  outline: none;
}
textarea { min-height: 132px; resize: vertical; line-height: 1.45; }
input:focus, textarea:focus, select:focus { border-color: var(--red-2); box-shadow: 0 0 0 3px rgba(209,20,24,.14); }

.voice-field { gap: 10px; min-width: 0; max-width: 100%; }
.voice-input {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 72px 72px;
  gap: 10px;
  align-items: stretch;
  min-width: 0;
  max-width: 100%;
}
.voice-input textarea { min-width: 0; max-width: 100%; }
.mic-button, .magic-button {
  position: relative;
  z-index: 1;
  min-height: 132px;
  width: 72px;
  padding: 0;
  background: #fff7f7;
  border: 1px solid rgba(209,20,24,.35);
  color: var(--red);
  font-size: 26px;
  line-height: 1;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  pointer-events: auto;
}
.mic-button.recording { background: var(--red); color: #fff; box-shadow: 0 0 0 4px rgba(209,20,24,.16); }
.magic-button { background: #fff; color: var(--text); }
.voice-status { min-height: 20px; color: var(--red); font-weight: 900; }
.voice-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(41,38,36,.56);
}
.voice-dialog {
  width: min(860px, 100%);
  max-height: 92vh;
  overflow: auto;
  display: grid;
  gap: 14px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: var(--shadow);
}
.voice-dialog textarea { min-height: 140px; }
.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
}
.toggle-row input { width: 24px; min-height: 24px; }

.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
}
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px;
  border-right: 1px solid var(--line);
  background: rgba(255,255,255,.92);
  box-shadow: 8px 0 28px rgba(70,50,42,.08);
}
.brand { display: grid; gap: 10px; margin-bottom: 28px; min-width: 0; }
.brand span, .user-card small { display: block; color: var(--muted); font-size: 12px; margin-top: 4px; }
nav { display: grid; gap: 8px; }
nav button {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
}
nav button.active {
  border-color: rgba(209,20,24,.35);
  background: rgba(209,20,24,.08);
  color: var(--red);
}
.user-card {
  position: absolute;
  left: 22px;
  right: 22px;
  bottom: 22px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}
main { min-width: 0; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 24px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(250,248,243,.9);
  backdrop-filter: blur(16px);
}
.top-title { display: flex; align-items: center; gap: 16px; min-width: 0; }
.topbar-logo {
  width: min(260px, 42vw);
  max-height: 78px;
  height: auto;
  object-fit: contain;
  object-position: left center;
  display: block;
  flex: 0 0 auto;
}
.top-actions { display: flex; gap: 10px; align-items: center; min-width: 0; }
#search { width: min(420px, 42vw); }
#content { padding: 28px; min-width: 0; }
.sync-status {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 12px;
  color: var(--muted);
  background: #fff;
  font-weight: 800;
  font-size: 12px;
}
.sync-status.ok { color: var(--green); border-color: rgba(47,125,84,.35); }
.sync-status.warn { color: var(--amber); border-color: rgba(175,116,29,.35); }
.sync-status.error { color: var(--red); border-color: rgba(209,20,24,.42); }
.sync-status.busy { color: var(--text); border-color: rgba(41,38,36,.28); }
.sync-panel { margin: 18px 0; }
.dashboard-logo-panel {
  margin-top: 18px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
}
.dashboard-logo-panel img {
  width: min(520px, 100%);
  max-height: 170px;
  height: auto;
  object-fit: contain;
  object-position: left center;
  display: block;
}
.grid { display: grid; gap: 18px; min-width: 0; }
.stats { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.stat, .panel, .card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}
.stat { padding: 18px; min-height: 120px; }
.stat strong { display: block; margin-top: 16px; font-size: 30px; }
.stat span, .card small { color: var(--muted); }
.panel { padding: 18px; min-width: 0; }
.toolbar { display: flex; justify-content: space-between; gap: 12px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.cards { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.card { padding: 16px; display: grid; gap: 12px; min-width: 0; }
.card.local { border-color: rgba(175,116,29,.45); }
.card-row { display: flex; justify-content: space-between; gap: 12px; align-items: center; flex-wrap: wrap; }
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 4px 10px;
  border-radius: 999px;
  background: #f1ede6;
  font-size: 12px;
  font-weight: 900;
  color: var(--text);
}
.badge.red { background: rgba(209,20,24,.1); color: var(--red); }
.badge.green { background: rgba(47,125,84,.12); color: var(--green); }
.badge.amber { background: rgba(175,116,29,.14); color: var(--amber); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-grid .wide { grid-column: 1 / -1; }
.module-layout { display: grid; grid-template-columns: minmax(560px, .95fr) minmax(360px, 1fr); gap: 22px; align-items: start; }
.module-layout > section { min-width: 0; }
.module-layout > .panel .form-grid { grid-template-columns: 1fr; }
.table-wrap { overflow: visible; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
table { width: 100%; border-collapse: collapse; table-layout: fixed; }
th, td { padding: 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; white-space: normal; overflow-wrap: anywhere; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; }
.labor-block {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfaf6;
}
.labor-table { display: grid; gap: 10px; }
.labor-head,
.labor-row {
  display: grid;
  grid-template-columns: minmax(210px, 1.2fr) minmax(150px, .8fr) auto;
  gap: 10px;
  align-items: end;
}
.labor-head { color: var(--muted); font-size: 12px; font-weight: 900; text-transform: uppercase; }
.labor-row { padding: 10px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.labor-row button { min-width: 112px; }
.labor-total {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: rgba(209,20,24,.08);
}
.gallery { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.photo { aspect-ratio: 4 / 3; object-fit: cover; width: 100%; border-radius: var(--radius); border: 1px solid var(--line); background: #f5f2ec; }
.photo-upload-box {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
}
.file-button {
  min-height: 52px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  padding: 0 18px;
  cursor: pointer;
  font-weight: 900;
}
.file-button input { display: none; }
.photo-preview {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
}
.photo-preview figure { margin: 0; display: grid; gap: 6px; }
.photo-preview img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: var(--radius); border: 1px solid var(--line); }
.photo-preview figcaption { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.smtp-diagnostics {
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
}
.smtp-diagnostics small { display: block; overflow-wrap: anywhere; }
.doc-box { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.doc-box h4 { margin: 0 0 12px; color: var(--text); }
.doc-upload { display: grid; grid-template-columns: minmax(150px, 1fr) minmax(180px, 2fr) auto; gap: 10px; align-items: end; }
.doc-list { display: grid; gap: 10px; margin-top: 12px; }
.doc-row { display: flex; justify-content: space-between; gap: 12px; padding: 10px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel-soft); }
.doc-row span:first-child { min-width: 0; display: grid; gap: 4px; }
.doc-row strong { overflow-wrap: anywhere; }
.signature {
  width: 100%;
  height: 180px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  touch-action: none;
}
.acceptance-text {
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--red);
  border-radius: var(--radius);
  background: var(--panel-soft);
  color: var(--text);
  font-weight: 900;
}
.offline {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 30;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: #fff2d7;
  color: #5c3b05;
  border: 1px solid rgba(175,116,29,.24);
  font-weight: 900;
  box-shadow: var(--shadow);
}

@media (max-width: 1500px) {
  .app { grid-template-columns: 116px minmax(0, 1fr); }
  .sidebar {
    width: 116px;
    padding: 10px;
  }
  .brand, .user-card { display: none; }
  nav { grid-template-columns: 1fr; gap: 8px; }
  nav button {
    justify-content: center;
    flex-direction: column;
    min-height: 76px;
    padding: 8px 4px;
    font-size: 12px;
    border-color: var(--line);
    background: #fff;
    text-align: center;
  }
  nav button span { font-size: 16px; font-weight: 900; }
  nav button.active { border-color: var(--red); background: rgba(209,20,24,.08); box-shadow: inset 4px 0 0 var(--red); }
  .topbar { align-items: stretch; flex-direction: column; padding: 18px; }
  .top-actions { width: 100%; flex-wrap: wrap; }
  #search { width: 100%; }
  #content { padding: 18px; }
  .module-layout { grid-template-columns: minmax(560px, .95fr) minmax(360px, 1fr); gap: 18px; }
  th, td { padding: 12px; font-size: 13px; }
  table, thead, tbody, th, td, tr { display: block; width: 100%; }
  thead { display: none; }
  tr { padding: 12px; border-bottom: 1px solid var(--line); }
  td { border-bottom: 0; padding: 7px 0; }
  td::before { content: attr(data-label); display: block; color: var(--muted); font-size: 11px; font-weight: 900; text-transform: uppercase; margin-bottom: 3px; }
}

@media (max-width: 1280px) {
  .module-layout { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  .form-grid { grid-template-columns: 1fr; }
  .labor-head { display: none; }
  .labor-row { grid-template-columns: 1fr; }
  .labor-row button { width: 100%; }
  .doc-upload { grid-template-columns: 1fr; }
  .doc-row { display: grid; }
  .doc-row .toolbar { justify-content: stretch; }
}

@media (max-width: 640px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    z-index: 10;
    width: auto;
    height: auto;
    padding: 8px;
    border-right: 0;
    border-top: 1px solid var(--line);
  }
  nav { grid-template-columns: repeat(4, 1fr); gap: 6px; }
  nav button { min-height: 60px; font-size: 11px; }
  .login-panel { padding: 22px; }
  .stats { grid-template-columns: 1fr; }
  .top-actions { flex-direction: column; }
  .top-actions button, .sync-status { width: 100%; justify-content: center; }
  .top-title { width: 100%; }
  .topbar-logo { width: min(190px, 52vw); max-height: 64px; }
  #content { padding: 16px 16px 190px; }
  .voice-input { grid-template-columns: minmax(0, 1fr) 56px 56px; }
  .mic-button, .magic-button { width: 56px; min-height: 132px; }
}
