/* styles.css — оформление на CRM системата. Работи на компютър и телефон. */

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --ink: #0f172a;
  --muted: #64748b;
  --faint: #94a3b8;
  --border: #e4e8ee;
  --accent: #0f766e;
  --accent-hover: #0b5e57;
  --accent-soft: #e6f3f1;
  --green: #15803d;
  --green-soft: #dcfce7;
  --amber: #b45309;
  --amber-soft: #fef3c7;
  --red: #b91c1c;
  --red-soft: #fee2e2;
  --blue: #1d4ed8;
  --blue-soft: #dbeafe;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 4px 16px rgba(15, 23, 42, 0.05);
  --radius: 12px;
  --radius-sm: 8px;
  --company: #0f766e;
  --sidebar-w: 232px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 15px; }
a { color: var(--accent); }

/* ---------- Вход ---------- */
.auth-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1200px 500px at 20% -10%, #e8f1ef 0%, transparent 60%),
    var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 32px 28px;
}
.auth-logo {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 18px; letter-spacing: -0.02em;
  margin-bottom: 4px;
}
.auth-logo .mark {
  width: 30px; height: 30px; border-radius: 8px;
  background: var(--accent); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 16px;
}
.auth-sub { color: var(--muted); font-size: 14px; margin: 0 0 22px; }
.auth-tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 10px; margin-bottom: 20px; }
.auth-tabs button {
  flex: 1; border: 0; background: transparent; padding: 9px; border-radius: 7px;
  font-weight: 600; color: var(--muted);
}
.auth-tabs button.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

/* ---------- Форми ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink); outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.field textarea { resize: vertical; min-height: 72px; }
.field-row { display: flex; gap: 12px; }
.field-row > .field { flex: 1; }

.btn {
  border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 10px 16px; font-weight: 600; font-size: 14px;
  background: var(--accent); color: #fff;
  transition: background .15s, transform .05s;
}
.btn:hover { background: var(--accent-hover); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .6; cursor: default; }
.btn.full { width: 100%; }
.btn.ghost { background: var(--surface); color: var(--ink); border-color: var(--border); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { background: var(--surface); color: var(--red); border-color: var(--border); }
.btn.danger:hover { background: var(--red-soft); }
.btn.sm { padding: 6px 11px; font-size: 13px; }
.btn-row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }

.err { background: var(--red-soft); color: var(--red); padding: 9px 12px; border-radius: var(--radius-sm); font-size: 14px; margin-bottom: 14px; }

/* ---------- Структура ---------- */
.app { display: flex; min-height: 100vh; }
.company-bar { position: fixed; top: 0; left: 0; right: 0; height: 4px; background: var(--company); z-index: 60; }

.sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  background: var(--surface); border-right: 1px solid var(--border);
  position: fixed; top: 0; bottom: 0; left: 0; padding-top: 4px;
  display: flex; flex-direction: column; z-index: 50;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; font-weight: 700; letter-spacing: -0.02em; }
.brand .mark { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 15px; }
.nav { padding: 6px 10px; flex: 1; overflow-y: auto; }
.nav button {
  display: flex; align-items: center; gap: 11px; width: 100%;
  border: 0; background: transparent; color: var(--muted);
  padding: 10px 12px; border-radius: var(--radius-sm); font-weight: 600; font-size: 14px;
  margin-bottom: 2px; text-align: left;
}
.nav button .ic { width: 18px; text-align: center; opacity: .9; }
.nav button:hover { background: var(--surface-2); color: var(--ink); }
.nav button.active { background: var(--accent-soft); color: var(--accent); }
.nav .badge { margin-left: auto; background: var(--red); color: #fff; font-size: 11px; border-radius: 20px; padding: 1px 7px; font-weight: 700; }

.content { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; min-width: 0; }

.topbar {
  position: sticky; top: 0; z-index: 40;
  background: rgba(255,255,255,0.85); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 14px; padding: 12px 22px;
}
.topbar h1 { font-size: 18px; margin: 0; letter-spacing: -0.02em; flex: 1; }

.company-select { position: relative; }
.company-pill {
  display: flex; align-items: center; gap: 9px;
  border: 1px solid var(--border); background: var(--surface);
  padding: 7px 12px; border-radius: 30px; font-weight: 600; font-size: 14px;
}
.company-pill .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--company); }
.company-pill .chev { color: var(--faint); font-size: 12px; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 220px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 6px; z-index: 70;
}
.menu button { display: flex; align-items: center; gap: 9px; width: 100%; border: 0; background: transparent; text-align: left; padding: 9px 11px; border-radius: var(--radius-sm); font-size: 14px; color: var(--ink); }
.menu button:hover { background: var(--surface-2); }
.menu .dot { width: 9px; height: 9px; border-radius: 50%; }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 6px 4px; }

.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; font-size: 14px; border: 0; }

.page { padding: 22px; max-width: 1180px; width: 100%; }

/* ---------- Карти / таблици ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.stat .label { color: var(--muted); font-size: 13px; font-weight: 600; }
.stat .value { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; margin-top: 4px; }
.stat .sub { font-size: 12px; color: var(--faint); margin-top: 2px; }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.panel-head { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.panel-head h2 { font-size: 16px; margin: 0; flex: 1; letter-spacing: -0.01em; }
.search { flex: 0 1 240px; }
.search input { width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: 30px; outline: none; }
.search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--faint); padding: 11px 18px; border-bottom: 1px solid var(--border); font-weight: 700; }
td { padding: 13px 18px; border-bottom: 1px solid var(--border); font-size: 14px; vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); cursor: pointer; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

.tag { display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 12px; font-weight: 700; }
.tag.green { background: var(--green-soft); color: var(--green); }
.tag.amber { background: var(--amber-soft); color: var(--amber); }
.tag.red { background: var(--red-soft); color: var(--red); }
.tag.blue { background: var(--blue-soft); color: var(--blue); }
.tag.gray { background: var(--surface-2); color: var(--muted); }

.empty { padding: 48px 20px; text-align: center; color: var(--muted); }
.empty .big { font-size: 32px; margin-bottom: 8px; }

/* ---------- Фуния (сделки) ---------- */
.pipeline { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 8px; }
.col { flex: 0 0 250px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; }
.col-head { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 13px; margin-bottom: 10px; padding: 0 4px; }
.col-head .count { margin-left: auto; color: var(--faint); font-weight: 600; }
.deal-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 11px 12px; margin-bottom: 8px; box-shadow: var(--shadow); cursor: grab; }
.deal-card.dragging { opacity: .5; }
.deal-card .t { font-weight: 600; font-size: 14px; }
.deal-card .v { color: var(--accent); font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.deal-card .c { color: var(--muted); font-size: 13px; margin-top: 2px; }
.col.drop-target { outline: 2px dashed var(--accent); outline-offset: -2px; }

/* ---------- Модал ---------- */
.overlay { position: fixed; inset: 0; background: rgba(15,23,42,0.45); z-index: 100; display: grid; place-items: center; padding: 20px; }
.modal { background: var(--surface); border-radius: 16px; width: 100%; max-width: 540px; max-height: 90vh; overflow: hidden; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(15,23,42,0.3); }
.modal.wide { max-width: 760px; }
.modal-head { display: flex; align-items: center; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 17px; flex: 1; letter-spacing: -0.01em; }
.modal-head .x { border: 0; background: transparent; font-size: 22px; color: var(--faint); line-height: 1; }
.modal-body { padding: 20px 22px; overflow-y: auto; }
.modal-foot { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }

/* редове на фактура */
.items th { padding: 7px 8px; }
.items td { padding: 5px 6px; border: 0; }
.items input { padding: 8px 9px; }
.items .num input { text-align: right; }
.totals { margin-top: 12px; margin-left: auto; width: 260px; }
.totals .line { display: flex; justify-content: space-between; padding: 4px 0; font-variant-numeric: tabular-nums; }
.totals .line.grand { font-weight: 700; font-size: 17px; border-top: 1px solid var(--border); margin-top: 6px; padding-top: 8px; }

/* toast */
.toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 30px; font-size: 14px; box-shadow: var(--shadow); animation: pop .2s ease; }
.toast.err { background: var(--red); }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

.detail-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 18px; margin-bottom: 18px; }
.detail-meta .k { font-size: 12px; color: var(--faint); text-transform: uppercase; letter-spacing: .04em; font-weight: 700; }
.detail-meta .v { font-size: 15px; }
.timeline { border-left: 2px solid var(--border); margin-left: 6px; padding-left: 16px; }
.timeline .item { margin-bottom: 16px; position: relative; }
.timeline .item::before { content: ''; position: absolute; left: -23px; top: 4px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.timeline .when { font-size: 12px; color: var(--faint); }

/* мобилна навигация */
.mobile-nav { display: none; }
.hamburger { display: none; }
.scrim { display: none; }

@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .content { margin-left: 0; }
  .hamburger { display: inline-grid; place-items: center; width: 36px; height: 36px; border: 1px solid var(--border); background: var(--surface); border-radius: 9px; font-size: 18px; }
  .scrim.show { display: block; position: fixed; inset: 0; background: rgba(15,23,42,0.4); z-index: 45; }
  .topbar h1 { font-size: 16px; }
  .page { padding: 16px; padding-bottom: 80px; }
  .field-row { flex-direction: column; gap: 0; }
  .detail-meta { grid-template-columns: 1fr; }
  .hide-sm { display: none; }
}

/* ---------- Печат на фактура ---------- */
#print-area { display: none; }
@media print {
  body * { visibility: hidden; }
  #print-area, #print-area * { visibility: visible; }
  #print-area { display: block; position: absolute; inset: 0; padding: 28px 32px; background: #fff; color: #000; }
  .toasts, .overlay { display: none !important; }
}
.inv {
  font-size: 13px; color: #111; max-width: 820px; margin: 0 auto;
}
.inv-top { display: flex; justify-content: space-between; gap: 24px; margin-bottom: 26px; }
.inv-top .firm h2 { margin: 0 0 6px; font-size: 18px; }
.inv-top .meta { text-align: right; }
.inv-top .meta .big { font-size: 22px; font-weight: 800; letter-spacing: -0.01em; }
.inv-parties { display: flex; gap: 24px; margin-bottom: 22px; }
.inv-parties > div { flex: 1; border: 1px solid #ddd; border-radius: 8px; padding: 12px 14px; }
.inv-parties .ttl { font-size: 11px; text-transform: uppercase; color: #888; font-weight: 700; letter-spacing: .05em; margin-bottom: 6px; }
.inv table { width: 100%; border-collapse: collapse; margin-bottom: 14px; }
.inv th { background: #f3f4f6; text-align: left; padding: 9px 10px; font-size: 11px; text-transform: uppercase; color: #444; border-bottom: 1px solid #ddd; }
.inv td { padding: 9px 10px; border-bottom: 1px solid #eee; }
.inv .r { text-align: right; font-variant-numeric: tabular-nums; }
.inv-tot { width: 280px; margin-left: auto; }
.inv-tot .l { display: flex; justify-content: space-between; padding: 4px 0; }
.inv-tot .l.g { font-weight: 800; font-size: 16px; border-top: 2px solid #111; margin-top: 6px; padding-top: 8px; }
.inv-sign { display: flex; justify-content: space-between; margin-top: 40px; font-size: 12px; color: #555; }
.inv-pay { margin: 16px 0; font-size: 12px; color: #333; }
