:root {
  --bg: #f3f0ea;
  --paper: #ffffff;
  --ink: #161616;
  --muted: #6d6a64;
  --line: #ddd8ce;
  --sidebar: #141414;
  --sidebar-text: #f4f1ea;
  --accent: #b0894d;
  --danger: #9b2c2c;
  --ok: #2f6b4f;
  --shadow: 0 18px 50px rgba(20, 20, 20, 0.08);
  font-family: "Avenir Next", "Segoe UI", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { color: var(--ink); background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.03em; }
p { margin: 0; }
a { color: inherit; }

.auth-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at top, rgba(176, 137, 77, 0.16), transparent 28%), #111;
  color: #f7f4ee;
}
.auth-card {
  width: min(440px, calc(100vw - 32px));
  background: #1b1b1b;
  border: 1px solid #2a2a2a;
  padding: 36px 32px;
  box-shadow: 0 24px 80px rgba(0,0,0,.35);
}
.auth-kicker {
  text-transform: uppercase;
  letter-spacing: 0.22em;
  font-size: 11px;
  color: var(--accent);
  margin-bottom: 10px;
}
.auth-lead { color: #bdb7ad; margin: 10px 0 24px; line-height: 1.45; }
.auth-form { display: grid; gap: 14px; }
.auth-form button {
  background: #f4f1ea;
  color: #111;
  font-weight: 600;
  padding: 12px;
  border: 0;
  border-radius: 8px;
}
label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.auth-form label { color: #cfc9bf; }
input, select, textarea {
  border: 1px solid var(--line);
  background: #fff;
  padding: 10px 12px;
  border-radius: 8px;
  width: 100%;
}
textarea { min-height: 110px; resize: vertical; }
.auth-form input {
  background: #111;
  border-color: #333;
  color: #fff;
}
.form-error { color: #e8b4b4; font-size: 13px; }
.app-body .form-error { color: var(--danger); }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.app-body {
  display: grid;
  grid-template-columns: 260px 1fr;
  height: 100vh;
  max-height: 100vh;
  overflow: hidden;
}
.sidebar {
  background: var(--sidebar);
  color: var(--sidebar-text);
  padding: 28px 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-height: 0;
  overflow: auto;
}
.brand { display: flex; gap: 12px; align-items: center; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px;
  display: grid; place-items: center;
  background: var(--accent); color: #111; font-weight: 700;
}
.brand small { display: block; color: #a8a49c; font-size: 12px; }
nav { display: grid; gap: 4px; }
.nav-btn, .logout, .ghost, .primary, .hub-link {
  border: 0;
  border-radius: 8px;
  padding: 10px 12px;
  text-align: left;
  text-decoration: none;
}
.nav-btn { background: transparent; color: #d7d2c8; }
.nav-btn.is-active, .nav-btn:hover { background: #222; color: #fff; }
.sidebar-end { margin-top: auto; display: grid; gap: 8px; }
.hub-link { color: #a8a49c; font-size: 13px; }
.hub-link:hover { color: #fff; }
.logout {
  background: transparent;
  color: #a8a49c;
  border: 1px solid #333;
}
.main { padding: 32px 36px 40px; overflow: auto; min-height: 0; }
.view-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 22px;
}
.view-header p { color: var(--muted); margin-top: 6px; max-width: 640px; line-height: 1.45; }
.header-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.primary { background: var(--ink); color: #fff; }
.ghost { background: transparent; border: 1px solid var(--line); }
.danger { background: transparent; border: 1px solid #e2c4c4; color: var(--danger); }
.danger.compact { font-size: 12px; padding: 5px 9px; }
.row-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}
.stat {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.stat strong { display: block; font-size: 28px; letter-spacing: -0.04em; }
.stat span { color: var(--muted); font-size: 13px; }

.panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
  box-shadow: var(--shadow);
}
.company-cards { display: grid; gap: 18px; }
.company-card { display: grid; grid-template-columns: 1fr; gap: 18px; align-items: start; }
.grid-2 { display: grid; grid-template-columns: 1.3fr .9fr; gap: 18px; align-items: start; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.stack { display: grid; gap: 14px; }
.search { width: 100%; margin-bottom: 16px; }
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
  align-items: flex-end;
}
.filters label {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 6px;
  margin: 0;
  font-size: 12px;
  min-width: 0;
}
.filters .grow { flex: 1 1 200px; }
.filters .mini { flex: 0 1 140px; }
.filters input,
.filters select {
  height: 42px;
  width: 100%;
}
.combo {
  position: relative;
  min-width: 0;
}
.combo-input { width: 100%; }
.combo-list {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  z-index: 40;
  max-height: 280px;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 6px;
}
.combo-heading, .combo-empty {
  margin: 0;
  padding: 8px 10px;
  font-size: 12px;
  color: var(--muted);
}
.combo-item {
  display: grid;
  gap: 2px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 8px;
  padding: 8px 10px;
}
.combo-item:hover, .combo-item.is-active { background: #f7f2e8; }
.combo-item strong { font-size: 14px; }
.combo-item span { font-size: 12px; color: var(--muted); }
.dialog-form .combo-list { max-height: 220px; }

.table-wrap { overflow: auto; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td { padding: 12px 10px; text-align: left; border-bottom: 1px solid var(--line); font-size: 14px; }
.data-table th {
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--muted); font-weight: 600;
}
.data-table tr.clickable { cursor: pointer; }
.data-table tr.clickable:hover { background: #faf7f1; }
.empty { color: var(--muted); text-align: center; padding: 36px 16px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 12px;
  background: #efe8da;
  color: #5a4a2d;
}
.badge.outlook { background: #e4eef8; color: #1f4e79; }
.badge.google, .badge.samsung { background: #e6f2ea; color: #215c38; }
.badge.local { background: #eeeae2; color: #444; }
.badge.ok { background: #e5f3ea; color: var(--ok); }
.badge.warn { background: #f8ead4; color: #8a5a12; }
.badge.danger { background: #f6e4e4; color: var(--danger); }

.person-dot {
  width: 10px; height: 10px; border-radius: 50%; display: inline-block;
}

.main.is-calendar {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  padding: 16px 20px 10px;
}
.main.is-calendar #app {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.cal-header { margin-bottom: 10px; flex: 0 0 auto; }
.main.is-calendar .view-header { margin-bottom: 10px; }
.cal-board {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 6px;
}
.cal-nav { display: flex; align-items: center; gap: 10px; }
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
}
.cal-weeks {
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-rows: repeat(6, minmax(0, 1fr));
  gap: 8px;
}
.cal-week {
  position: relative;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
}
.cal-dow {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  padding: 2px 6px;
}
.cal-day {
  min-height: 0;
  height: 100%;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.cal-day.out { opacity: .45; }
.cal-day.today { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.cal-day .num { font-size: 12px; font-weight: 600; flex: 0 0 auto; }
.cal-week-lanes {
  position: absolute;
  z-index: 1;
  left: 0;
  right: 0;
  top: 26px;
  bottom: 4px;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  grid-auto-rows: 22px;
  align-content: start;
  gap: 3px 8px;
  overflow: auto;
  pointer-events: none;
}
.cal-event {
  pointer-events: auto;
  border: 0;
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 12px;
  line-height: 1.25;
  color: #fff;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.cal-event.is-span {
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .12);
}

.dropzone {
  border: 1.5px dashed #c9c1b2;
  border-radius: 14px;
  padding: 28px 18px;
  text-align: center;
  background: #faf7f1;
  color: var(--muted);
  transition: .15s ease;
}
.dropzone.is-over { border-color: var(--accent); background: #f4ead6; color: var(--ink); }
.dropzone strong { color: var(--ink); display: block; margin-bottom: 4px; }

.files {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}
.file-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: #fff;
  position: relative;
}
.file-card img { width: 100%; height: 110px; object-fit: cover; display: block; }
.file-card .meta { padding: 8px 10px 10px; font-size: 12px; }
.file-card .meta a { text-decoration: underline; text-underline-offset: 2px; }
.file-card .del {
  position: absolute; top: 6px; right: 6px;
  background: rgba(20,20,20,.75); color: #fff; border: 0;
  border-radius: 6px; padding: 2px 7px; font-size: 12px;
}

.note {
  border-bottom: 1px solid var(--line);
  padding: 12px 0;
}
.note:last-child { border-bottom: 0; }
.note header { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.note p { white-space: pre-wrap; line-height: 1.45; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.dialog-form { display: grid; gap: 12px; }

dialog.sheet {
  border: 0;
  border-radius: 16px;
  padding: 0;
  width: min(720px, 94vw);
  max-height: 92vh;
  overflow: auto;
  box-shadow: var(--shadow);
}
dialog.sheet.is-wide { width: min(920px, 96vw); }
.sheet-sub { margin: 8px 0 0; font-size: 16px; }
.quote-line {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  margin: 10px 0;
  display: grid;
  gap: 10px;
  background: #faf7f1;
}
.zefix-field { position: relative; }
.zefix-hint { margin: 4px 0 0; }
.zefix-list { z-index: 50; }
.quote-line-search { position: relative; }
.quote-line .prod-list { max-height: 200px; }
dialog.sheet::backdrop { background: rgba(20,20,20,.45); }
.sheet-body { padding: 24px; display: grid; gap: 16px; }
.sheet-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }

.help {
  background: #f7f2e8;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 13px;
  line-height: 1.5;
  color: #4d4a44;
}
.help ol { margin: 8px 0 0 18px; padding: 0; }
.list-row {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--line); align-items: start;
}
.list-row:last-child { border-bottom: 0; }

.toast {
  position: fixed; right: 18px; bottom: 18px;
  background: #161616; color: #fff;
  padding: 12px 16px; border-radius: 10px;
  box-shadow: var(--shadow); z-index: 20;
}

@media (max-width: 980px) {
  .app-body { grid-template-columns: 1fr; height: auto; max-height: none; overflow: visible; }
  .sidebar { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 10px; }
  nav { display: flex; flex-wrap: wrap; gap: 4px; }
  .sidebar-end { margin-top: 0; }
  .hub-link, .logout { margin-top: 0; }
  .main { padding: 20px 16px 48px; }
  .grid-2, .grid-3, .form-grid { grid-template-columns: 1fr; }
  .filters { flex-direction: column; align-items: stretch; }
  .filters .grow, .filters .mini { flex: 1 1 auto; }
  .main.is-calendar {
    height: calc(100dvh - 150px);
    min-height: 640px;
    overflow: hidden;
    padding: 16px 12px 12px;
  }
  .cal-board { min-height: 0; }
  .cal-day { min-height: 0; }
  .view-header { flex-direction: column; }
}
