/* ===================================================================
   Chuchm Dashboard — Clean Dark v2
   =================================================================== */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 19px; -webkit-text-size-adjust: 100%; letter-spacing: 0.02em; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #111827;
  color: #f1f5f9;
  min-height: 100vh;
  line-height: 1.65;
  letter-spacing: 0.015em;
}

a { color: #60a5fa; text-decoration: none; }
a:hover { color: #93bbfd; }

/* ===== NAV ===== */
nav {
  background: rgba(17, 24, 39, 0.95);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  position: sticky;
  top: 0;
  z-index: 100;
}
.nav-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.nav-logo {
  font-size: 1.25rem;
  font-weight: 700;
  color: #f1f5f9;
  text-decoration: none;
  letter-spacing: -0.01em;
}
.nav-links { display: flex; gap: 2px; flex-shrink: 0; }
.nav-link {
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  text-decoration: none;
  color: #94a3b8;
  transition: background 0.15s, color 0.15s;
}
.nav-link:hover { background: rgba(255,255,255,0.05); color: #e2e8f0; }
.nav-link.active { background: rgba(59,130,246,0.15); color: #60a5fa; }
.nav-icon { margin-right: 4px; }

/* ===== FONT SLIDER ===== */
.font-slider-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
.font-btn {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 6px;
  background: #1e293b;
  color: #e2e8f0;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  user-select: none;
  line-height: 1;
}
.font-btn:hover { background: #273449; border-color: rgba(255,255,255,0.25); }
.font-btn:disabled { opacity: 0.3; cursor: default; }
.font-size-display {
  min-width: 22px;
  text-align: center;
  font-size: 0.8rem;
  font-weight: 600;
  color: #94a3b8;
  font-variant-numeric: tabular-nums;
}

/* ===== MAIN ===== */
main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 20px 16px 60px;
}

/* ===== STAT CARDS ===== */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  margin-bottom: 20px;
}
@media (max-width: 700px) { .stat-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 400px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }

.stat-card {
  background: #1e293b;
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 10px;
  padding: 10px 10px;
}
.stat-label {
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #64748b;
  margin-bottom: 3px;
}
.stat-value {
  font-size: 1.05rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.stat-value.green { color: #22c55e; }
.stat-value.blue  { color: #3b82f6; }
.stat-value.amber { color: #f59e0b; }
.stat-value.red   { color: #ef4444; }

/* ===== SECTION HEADERS ===== */
.section-hdr {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 24px 0 10px;
}
.section-hdr:first-of-type { margin-top: 0; }
.section-title {
  font-size: 1rem;
  font-weight: 600;
  color: #e2e8f0;
}
.section-title .dot { color: #22c55e; }
.section-title .dot.done { color: #60a5fa; }
.section-link {
  font-size: 0.82rem;
  color: #60a5fa;
  font-weight: 500;
}

/* ===== FILTER BAR ===== */
.filter-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  align-items: center;
}
.filter-input {
  flex: 1;
  max-width: 320px;
  padding: 10px 14px;
  font-size: 0.9rem;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.08);
  background: #1e293b;
  color: #f1f5f9;
  outline: none;
}
.filter-input:focus { border-color: #3b82f6; }
.filter-input::placeholder { color: #475569; }
.filter-select {
  padding: 10px 14px;
  font-size: 0.85rem;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.08);
  background: #1e293b;
  color: #f1f5f9;
  outline: none;
  cursor: pointer;
}
.btn-add {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px; height: 40px;
  font-size: 1.3rem;
  border-radius: 8px;
  border: 1px solid #3b82f6;
  background: rgba(59,130,246,0.1);
  color: #3b82f6;
  text-decoration: none;
  flex-shrink: 0;
}
.btn-add:hover { background: #3b82f6; color: #fff; }

/* ===== ORDER ROW (compact accordion) ===== */
.order-card {
  background: #1e293b;
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 10px;
  margin-bottom: 6px;
  overflow: hidden;
}

.order-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  cursor: pointer;
  user-select: none;
  transition: background 0.1s;
}
.order-row:hover { background: rgba(255,255,255,0.03); }

.order-status-icon {
  flex-shrink: 0;
  font-size: 1.05rem;
  line-height: 1;
}

.order-name {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  font-size: 0.95rem;
  line-height: 1.35;
  word-break: break-word;
  color: #f1f5f9;
}

.order-row-amount {
  flex-shrink: 0;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-weight: 700;
  font-size: 0.9rem;
  color: #60a5fa;
  white-space: nowrap;
}

.order-arrow {
  flex-shrink: 0;
  color: #475569;
  font-size: 0.65rem;
  transition: transform 0.2s;
}
.order-arrow.open { transform: rotate(90deg); }

/* ===== ORDER BODY (accordion content) ===== */
.order-body { display: none; }
.order-body.open { display: block; }

.order-body-inner {
  padding: 0 14px 16px;
  border-top: 1px solid rgba(255,255,255,0.06);
}

/* Description */
.order-desc {
  padding: 12px 0;
  font-size: 0.88rem;
  color: #cbd5e1;
  line-height: 1.6;
}

/* Meta row */
.order-meta {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  font-size: 0.82rem;
  color: #64748b;
  padding-bottom: 8px;
}
.order-meta .phone { color: #60a5fa; font-weight: 500; }

/* ===== EXPENSE TABLE (horizontal categories, vertical Plan/Fact) ===== */
.expense-block {
  margin: 12px 0 0;
}
.expense-block-title {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #94a3b8;
  margin-bottom: 8px;
}

.expense-h-grid {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
}
.expense-col {
  background: #0f172a;
  border: 1px solid rgba(255,255,255,0.05);
  border-radius: 8px;
  min-width: 120px;
  flex: 1;
  text-align: center;
  overflow: hidden;
}
.expense-col-header {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #94a3b8;
  padding: 8px 10px 4px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  white-space: nowrap;
}
.expense-col-row {
  display: flex;
  justify-content: space-between;
  padding: 5px 10px;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
}
.expense-col-row.plan { color: #60a5fa; }
.expense-col-row.fact { color: #22c55e; }
.expense-col-row .row-label {
  font-weight: 500;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.expense-col-row .row-val {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-weight: 600;
}

/* Total row */
.expense-total-row {
  display: flex;
  gap: 8px;
  margin-top: 6px;
  overflow-x: auto;
}
.expense-total-col {
  min-width: 120px;
  flex: 1;
  text-align: center;
  padding: 6px 10px;
  font-size: 0.85rem;
  font-weight: 700;
  font-family: 'SF Mono', 'Fira Code', monospace;
  border-top: 1px solid rgba(255,255,255,0.1);
}
.expense-total-col.plan { color: #60a5fa; }
.expense-total-col.fact { color: #22c55e; }
.expense-total-col .total-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #94a3b8;
  display: block;
  margin-bottom: 2px;
}

/* ===== ORDER FINANCE SUMMARY ===== */
.order-finance {
  margin: 10px 0 0;
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  padding: 8px 0;
  border-top: 1px solid rgba(255,255,255,0.06);
}
.fin-item {
  text-align: center;
  min-width: 80px;
}
.fin-item-label {
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #64748b;
}
.fin-item-val {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-weight: 700;
  font-size: 0.9rem;
}
.fin-item-val.green { color: #22c55e; }
.fin-item-val.red   { color: #ef4444; }
.fin-item-val.blue  { color: #60a5fa; }

/* ===== ORDER ACTIONS ===== */
.order-actions {
  display: flex;
  gap: 6px;
  padding: 10px 0 0;
  border-top: 1px solid rgba(255,255,255,0.06);
  margin-top: 8px;
}

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 8px 14px;
  font-size: 0.82rem; font-weight: 500;
  border-radius: 8px; border: 1px solid rgba(255,255,255,0.08);
  background: #1e293b; color: #e2e8f0;
  cursor: pointer; text-decoration: none;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: #273449; border-color: rgba(255,255,255,0.15); }
.btn-sm { padding: 5px 10px; font-size: 0.78rem; border-radius: 6px; }
.btn-blue { border-color: #3b82f6; color: #60a5fa; }
.btn-blue:hover { background: rgba(59,130,246,0.12); }
.btn-green { border-color: #22c55e; color: #22c55e; }
.btn-green:hover { background: rgba(34,197,94,0.1); }
.btn-red { border-color: rgba(239,68,68,0.3); color: #ef4444; }
.btn-red:hover { background: rgba(239,68,68,0.08); }
.btn-primary { background: #3b82f6; color: #fff; border-color: #3b82f6; }
.btn-primary:hover { background: #2563eb; }

/* ===== PAGE HEADER ===== */
.page-hdr {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.page-title {
  font-size: 1.1rem;
  font-weight: 700;
}

/* ===== HOME PAGE ===== */
.home-orders-list { margin-top: 12px; }

.home-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 20px;
}
@media (max-width: 500px) { .home-cards { grid-template-columns: 1fr; } }
.home-card {
  background: #1e293b;
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 10px;
  padding: 16px;
  text-decoration: none;
  display: block;
  transition: border-color 0.15s;
}
.home-card:hover { border-color: rgba(59,130,246,0.2); }
.home-card-icon { font-size: 1.5rem; margin-bottom: 6px; }
.home-card-title { font-size: 0.95rem; font-weight: 600; color: #f1f5f9; margin-bottom: 4px; }
.home-card-desc { font-size: 0.8rem; color: #94a3b8; line-height: 1.5; }

/* ===== CLIENTS ===== */
.clients-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 8px;
}
.client-card {
  background: #1e293b;
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 10px;
  padding: 14px;
}
.client-card-name { font-weight: 600; font-size: 0.92rem; margin-bottom: 4px; }
.client-card-info { font-size: 0.8rem; color: #94a3b8; }
.client-card-orders { font-size: 0.75rem; color: #64748b; margin-top: 4px; }

/* ===== FINANCE ===== */
.finance-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 20px;
}
@media (max-width: 600px) { .finance-grid { grid-template-columns: 1fr; } }

.finance-cat-list { list-style: none; }
.finance-cat-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 7px 0; border-bottom: 1px solid rgba(255,255,255,0.04);
  font-size: 0.85rem;
}
.finance-cat-item:last-child { border-bottom: none; }
.finance-cat-amount { font-family: 'SF Mono', 'Fira Code', monospace; font-weight: 500; }

.transactions-table {
  width: 100%; border-collapse: collapse; font-size: 0.85rem;
}
.transactions-table th {
  text-align: left; padding: 8px 10px;
  font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.04em;
  color: #64748b; border-bottom: 1px solid rgba(255,255,255,0.06);
  font-weight: 600;
}
.transactions-table td { padding: 8px 10px; border-bottom: 1px solid rgba(255,255,255,0.04); }
.amount-green { color: #22c55e; font-weight: 600; }
.amount-red { color: #ef4444; font-weight: 600; }

/* ===== FORMS ===== */
.form-group { margin-bottom: 14px; }
.form-label {
  display: block;
  font-size: 0.8rem; font-weight: 500;
  color: #94a3b8;
  margin-bottom: 4px;
}
.form-input, .form-textarea, .form-select {
  width: 100%;
  padding: 10px 14px;
  font-size: 0.9rem;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.08);
  background: #1e293b;
  color: #f1f5f9;
  outline: none;
  font-family: inherit;
}
.form-input:focus, .form-textarea:focus { border-color: #3b82f6; }
.form-textarea { min-height: 80px; resize: vertical; line-height: 1.6; }
.form-actions { display: flex; gap: 8px; margin-top: 16px; }

/* ===== RESPONSIVE ===== */
@media (max-width: 600px) {
  html { font-size: 18px; letter-spacing: 0.02em; }
  main { padding: 12px 10px 50px; }
  .nav-label { display: none; }
  .order-row { gap: 6px; padding: 8px 10px; }
  .order-name { font-size: 0.95rem; }
  .order-row-amount { font-size: 0.82rem; }
  .order-status-icon { font-size: 0.95rem; }
  .order-body-inner { padding: 0 10px 12px; }
}

/* ===== ПЛАН/ФАКТ ТАБЛИЦА ===== */
.pt-table-wrap {
  margin: 12px 0 0;
  overflow-x: auto;
}
.pt-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  font-variant-numeric: tabular-nums;
}
.pt-table th {
  text-align: left;
  padding: 8px 10px;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #64748b;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  font-weight: 600;
}
.pt-th-label { width: 50%; }
.pt-th-num { width: 25%; text-align: right; }

.pt-table td {
  padding: 7px 10px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}
.pt-td-label {
  color: #cbd5e1;
  font-weight: 500;
}
.pt-td-num {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-weight: 700;
  text-align: right;
}
.pt-td-num.plan { color: #60a5fa; }
.pt-td-num.fact { color: #22c55e; }

/* Цвета строк по типу */
.pt-row-sum td { background: rgba(59,130,246,0.05); }
.pt-row-sum .pt-td-label { color: #93bbfd; font-weight: 700; }
.pt-row-expense td { }
.pt-row-tax td { }
.pt-row-tax .pt-td-label { color: #f59e0b; }
.pt-row-overhead td { }
.pt-row-overhead .pt-td-label { color: #94a3b8; }
.pt-row-profit td { border-top: 1px solid rgba(255,255,255,0.1); }
.pt-row-profit .pt-td-label { color: #22c55e; font-weight: 700; }
.pt-row-profit .pt-td-num { color: #22c55e; }
.pt-row-percent td { }
.pt-row-percent .pt-td-label { color: #94a3b8; }
.pt-row-percent .pt-td-num { color: #94a3b8; }

/* ===== ЧАТ ===== */
html.chat-page, html.chat-page body { overflow: hidden; height: 100%; position: fixed; width: 100%; }
#chat-app { display: flex; flex-direction: column; height: 100dvh; max-width: 900px; margin: 0 auto; width: 100%; }
#chat-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; padding-top: calc(12px + env(safe-area-inset-top, 0px)); border-bottom: 1px solid rgba(255,255,255,0.08); flex-shrink: 0; }
.chat-header-info { display: flex; align-items: center; gap: 10px; }
.chat-avatar { width: 40px; height: 40px; border-radius: 50%; background: #3b82f6; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 1.1rem; color: #fff; }
.chat-name { font-size: 1rem; font-weight: 600; }
.chat-status { font-size: 0.75rem; color: #22c55e; }
#chat-clear { background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.1); border-radius: 8px; padding: 6px 10px; color: #94a3b8; cursor: pointer; font-size: 1rem; }
#chat-messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.chat-msg { max-width: 85%; padding: 12px 16px; border-radius: 12px; line-height: 1.6; font-size: 1rem; word-wrap: break-word; }
.chat-msg-user { align-self: flex-end; background: #2563eb; color: #fff; border-bottom-right-radius: 4px; }
.chat-msg-ai { align-self: flex-start; background: #1e293b; color: #e2e8f0; border-bottom-left-radius: 4px; }
.chat-msg-error { align-self: center; background: rgba(220,38,38,0.15); color: #fca5a5; border: 1px solid rgba(220,38,38,0.3); }
.chat-msg pre { background: #0f172a; padding: 10px; border-radius: 8px; overflow-x: auto; font-size: 0.9rem; margin: 8px 0; }
.chat-msg code { background: rgba(255,255,255,0.08); padding: 2px 6px; border-radius: 4px; font-size: 0.9rem; }
.chat-msg h3 { font-size: 1.1rem; margin: 8px 0 4px; color: #93bbfd; }
.chat-msg a { color: #60a5fa; text-decoration: underline; }
.chat-table { width: 100%; border-collapse: collapse; margin: 8px 0; font-size: 1rem; }
.chat-table th { background: #334155; color: #f1f5f9; padding: 8px 12px; text-align: left; font-weight: 600; border: 1px solid rgba(255,255,255,0.1); }
.chat-table td { padding: 6px 12px; border: 1px solid rgba(255,255,255,0.08); }
.chat-table tr:nth-child(even) td { background: rgba(255,255,255,0.03); }
.chat-table tr:hover td { background: rgba(59,130,246,0.08); }
.chat-empty { margin: auto; color: #475569; font-size: 1.1rem; }
.chat-typing { display: flex; gap: 4px; padding: 8px 16px; align-items: center; }
.typing-dot { width: 8px; height: 8px; background: #64748b; border-radius: 50%; animation: typin 1.4s infinite ease-in-out; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typin { 0%,60%,100% { transform: translateY(0); } 30% { transform: translateY(-6px); } }
#chat-input-area { display: flex; align-items: flex-end; gap: 8px; padding: 12px 16px 32px; padding-bottom: calc(32px + env(safe-area-inset-bottom, 16px)); border-top: 1px solid rgba(255,255,255,0.08); background: #0f172a; flex-shrink: 0; }
#chat-mic-btn { width: 40px; height: 40px; border-radius: 50%; border: none; background: #1e293b; font-size: 1.2rem; cursor: pointer; flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
#chat-mic-btn:hover { background: #334155; }
#chat-mic-btn.recording { background: #dc2626; }
#chat-input-wrap { flex: 1; }
#chat-input { width: 100%; padding: 10px 14px; border: 1px solid rgba(255,255,255,0.12); border-radius: 12px; background: #1e293b; color: #f1f5f9; font-size: 1rem; font-family: inherit; resize: none; outline: none; line-height: 1.4; }
#chat-input:focus { border-color: #3b82f6; }
#chat-send-btn { width: 40px; height: 40px; border-radius: 50%; border: none; background: #2563eb; color: #fff; font-size: 1.1rem; cursor: pointer; flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
#chat-send-btn:hover { background: #3b82f6; }
#chat-send-btn:disabled { opacity: 0.4; cursor: not-allowed; }
#chat-recording { display: flex; align-items: center; gap: 8px; padding: 8px 16px; background: rgba(220,38,38,0.1); justify-content: center; flex-shrink: 0; }
#chat-recording .rec-dot { width: 10px; height: 10px; background: #dc2626; border-radius: 50%; animation: blink 0.8s infinite; }
@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: 0.3; } }
#rec-cancel { background: none; border: none; color: #94a3b8; font-size: 1.2rem; cursor: pointer; }
.hidden { display: none !important; }
