/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --navy:      #1A2F4E;
  --navy-dark: #111F35;
  --navy-mid:  #243852;
  --navy-lite: #2E4A6A;
  --blue:      #2563EB;
  --blue-lite: #EFF6FF;
  --blue-mid:  #BFDBFE;
  --green:     #16A34A;
  --green-bg:  #DCFCE7;
  --amber:     #D97706;
  --amber-bg:  #FEF3C7;
  --red:       #DC2626;
  --red-bg:    #FEE2E2;
  --gray-50:   #F8FAFC;
  --gray-100:  #F1F5F9;
  --gray-200:  #E2E8F0;
  --gray-300:  #CBD5E1;
  --gray-400:  #94A3B8;
  --gray-500:  #64748B;
  --gray-600:  #475569;
  --gray-700:  #334155;
  --gray-800:  #1E293B;
  --gray-900:  #0F172A;
  --white:     #FFFFFF;
  --radius-sm: 4px;
  --radius:    6px;
  --radius-lg: 10px;
  --radius-xl: 14px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.06);
  --shadow:    0 2px 8px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 20px rgba(0,0,0,0.10);
}

html, body {
  height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  color: var(--gray-800);
  background: var(--gray-100);
  line-height: 1.5;
}

/* ===== APP SHELL ===== */
.app {
  display: grid;
  grid-template-columns: 220px 1fr;
  grid-template-rows: 100vh;
  height: 100vh;
  overflow: hidden;
}

/* ===== SIDEBAR ===== */
.sidebar {
  background: var(--navy-dark);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-brand {
  padding: 18px 16px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.07);
}

.brand-name {
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-name .brand-icon {
  width: 28px;
  height: 28px;
  background: var(--blue);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: #fff;
  flex-shrink: 0;
}

.brand-sub {
  font-size: 11px;
  color: rgba(255,255,255,0.35);
  margin-top: 3px;
  padding-left: 36px;
}

.sidebar-section-label {
  font-size: 10px;
  font-weight: 600;
  color: rgba(255,255,255,0.25);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 16px 16px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 500;
  color: rgba(255,255,255,0.55);
  cursor: pointer;
  border-left: 2px solid transparent;
  transition: all 0.15s;
  user-select: none;
}

.nav-item:hover {
  color: rgba(255,255,255,0.9);
  background: rgba(255,255,255,0.06);
}

.nav-item.active {
  color: #fff;
  background: rgba(37,99,235,0.25);
  border-left-color: var(--blue);
}

.nav-item .nav-icon {
  width: 18px;
  height: 18px;
  opacity: 0.7;
  flex-shrink: 0;
}

.nav-item.active .nav-icon { opacity: 1; }

.nav-badge {
  margin-left: auto;
  background: var(--blue);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 10px;
  min-width: 20px;
  text-align: center;
  display: none;
}

.sidebar-footer {
  margin-top: auto;
  padding: 12px 16px;
  border-top: 1px solid rgba(255,255,255,0.07);
}

.sidebar-contact {
  font-size: 11px;
  color: rgba(255,255,255,0.3);
  display: flex;
  align-items: center;
  gap: 6px;
  line-height: 1.6;
}

/* ===== MAIN CONTENT ===== */
.main {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--gray-100);
}

/* ===== TOPBAR ===== */
.topbar {
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  padding: 0 24px;
  height: 52px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}

.topbar-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--gray-800);
  letter-spacing: -0.01em;
}

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.doc-type-group {
  display: flex;
  background: var(--gray-100);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 2px;
  gap: 2px;
}

.doc-type-btn {
  padding: 5px 14px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  background: transparent;
  color: var(--gray-500);
  transition: all 0.15s;
  letter-spacing: 0.01em;
}

.doc-type-btn:hover { color: var(--gray-700); background: var(--gray-200); }
.doc-type-btn.active-q { background: var(--blue); color: #fff; }
.doc-type-btn.active-i { background: var(--green); color: #fff; }

/* ===== CONTENT AREA ===== */
.content {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
}

/* ===== PANE HIDDEN ===== */
.pane { display: none; }
.pane.active { display: block; }

/* ===== STATS ROW ===== */
.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  padding: 14px 18px;
  box-shadow: var(--shadow-sm);
}

.stat-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--gray-400);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 4px;
}

.stat-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--gray-800);
  letter-spacing: -0.02em;
}

.stat-card.highlight .stat-value { color: var(--blue); }

/* ===== CARDS ===== */
.card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--gray-100);
}

.card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-700);
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-title svg { color: var(--blue); }
.card-body { padding: 16px 20px; }

/* ===== FORM ===== */
.form-grid { display: grid; gap: 14px; }
.form-grid.col2 { grid-template-columns: 1fr 1fr; }
.form-grid.col3 { grid-template-columns: 1fr 1fr 1fr; }

.field label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 5px;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--gray-800);
  background: var(--white);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  font-family: inherit;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

.field textarea { resize: vertical; min-height: 70px; }

/* Markup global row */
.markup-global-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: var(--blue-lite);
  border-bottom: 1px solid var(--blue-mid);
}

.markup-global-row label {
  font-size: 12px;
  font-weight: 600;
  color: var(--gray-700);
  white-space: nowrap;
}

.markup-input-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}

.markup-input-wrap input {
  width: 72px;
  padding: 6px 10px;
  border: 1px solid var(--blue-mid);
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  color: var(--blue);
  background: var(--white);
  outline: none;
  text-align: center;
  transition: border-color 0.15s;
}

.markup-input-wrap input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }
.markup-input-wrap span { font-size: 13px; font-weight: 600; color: var(--blue); }

.markup-preview {
  margin-left: auto;
  font-size: 12px;
  color: var(--gray-500);
}

.markup-preview strong { color: var(--green); }

/* ===== CATALOG SEARCH ===== */
.search-box-wrap {
  padding: 14px 20px;
  border-bottom: 1px solid var(--gray-100);
  position: relative;
}

.search-box-wrap svg {
  position: absolute;
  left: 32px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--gray-400);
  width: 15px;
  height: 15px;
}

.search-box-wrap input {
  width: 100%;
  padding: 8px 12px 8px 36px;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--gray-800);
  background: var(--gray-50);
  outline: none;
  transition: all 0.15s;
  font-family: inherit;
}

.search-box-wrap input:focus {
  background: var(--white);
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

/* ===== CATALOG LIST ===== */
.catalog-scroll { max-height: 480px; overflow-y: auto; padding: 0 20px 12px; }

.cat-section { margin-top: 14px; }

.cat-section-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--gray-400);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 4px 0 8px;
  border-bottom: 1px solid var(--gray-100);
  margin-bottom: 4px;
}

.prod-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.12s;
  border: 1px solid transparent;
  margin-bottom: 2px;
}

.prod-row:hover { background: var(--gray-50); }

.prod-row.selected {
  background: var(--blue-lite);
  border-color: var(--blue-mid);
}

.prod-checkbox {
  width: 16px;
  height: 16px;
  accent-color: var(--blue);
  cursor: pointer;
  flex-shrink: 0;
}

.prod-info { flex: 1; min-width: 0; }

.prod-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--gray-800);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.prod-spec {
  font-size: 11px;
  color: var(--gray-400);
  margin-top: 1px;
}

.prod-price {
  font-size: 13px;
  font-weight: 600;
  color: var(--blue);
  white-space: nowrap;
  flex-shrink: 0;
}

.prod-row.selected .prod-price { color: var(--navy); }

/* ===== ORDER TABLE ===== */
.order-table-wrap { overflow-x: auto; }

.order-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.order-table thead tr { background: var(--gray-50); border-bottom: 1px solid var(--gray-200); }

.order-table th {
  padding: 10px 14px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  color: var(--gray-400);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.order-table th.right,
.order-table td.right { text-align: right; }

.order-table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--gray-100);
  vertical-align: middle;
  color: var(--gray-700);
}

.order-table tbody tr:last-child td { border-bottom: none; }
.order-table tbody tr:hover td { background: var(--gray-50); }

.td-product-name { font-weight: 500; color: var(--gray-800); }
.td-product-spec { font-size: 11px; color: var(--gray-400); margin-top: 1px; }

.qty-input {
  width: 56px;
  padding: 5px 8px;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  text-align: center;
  color: var(--gray-800);
  background: var(--white);
  outline: none;
  font-family: inherit;
}

.qty-input:focus { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(37,99,235,0.1); }

.del-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--gray-300);
  padding: 4px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.del-btn:hover { color: var(--red); background: var(--red-bg); }

/* ===== TOTAL BAR ===== */
.total-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: var(--gray-50);
  border-top: 1px solid var(--gray-200);
}

.total-bar-left { font-size: 12px; color: var(--gray-400); }
.total-bar-amount { font-size: 20px; font-weight: 700; color: var(--gray-900); letter-spacing: -0.02em; }
.total-bar-amount span { font-size: 13px; font-weight: 500; color: var(--gray-500); margin-right: 4px; }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--gray-200);
  background: var(--white);
  color: var(--gray-700);
  transition: all 0.15s;
  user-select: none;
  letter-spacing: 0.01em;
  font-family: inherit;
  line-height: 1;
}

.btn:hover { background: var(--gray-50); border-color: var(--gray-300); }
.btn:active { transform: scale(0.98); }

.btn svg { width: 15px; height: 15px; flex-shrink: 0; }

.btn-primary { background: var(--blue); color: #fff; border-color: var(--blue); }
.btn-primary:hover { background: #1D4ED8; border-color: #1D4ED8; }

.btn-success { background: var(--green); color: #fff; border-color: var(--green); }
.btn-success:hover { background: #15803D; border-color: #15803D; }

.btn-sm { padding: 6px 12px; font-size: 12px; }

.btn-group {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--gray-400);
}

.empty-state svg {
  width: 40px;
  height: 40px;
  margin: 0 auto 10px;
  display: block;
  opacity: 0.4;
}

.empty-state p { font-size: 13px; }

/* ===== BADGE ===== */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.badge-q { background: var(--blue-lite); color: var(--blue); }
.badge-i { background: var(--green-bg); color: var(--green); }

/* ===== DOCUMENT PREVIEW ===== */
#doc-preview {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.doc-topbar {
  background: var(--navy-dark);
  padding: 16px 28px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

.doc-brand-name { font-size: 18px; font-weight: 700; color: #fff; letter-spacing: -0.01em; }
.doc-brand-sub { font-size: 11px; color: rgba(255,255,255,0.45); margin-top: 2px; }
.doc-brand-addr { font-size: 11px; color: rgba(255,255,255,0.35); margin-top: 1px; }
.doc-brand-phone { font-size: 11px; color: rgba(255,255,255,0.35); margin-top: 1px; }

.doc-type-stamp {
  text-align: right;
}

.doc-type-word {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.doc-type-word.q { color: #93C5FD; }
.doc-type-word.i { color: #86EFAC; }

.doc-meta { font-size: 11px; color: rgba(255,255,255,0.45); margin-top: 4px; line-height: 1.7; }
.doc-meta strong { color: rgba(255,255,255,0.7); }

.doc-body { padding: 22px 28px; }

.doc-to-block {
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 20px;
}

.doc-to-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--gray-400);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 6px;
}

.doc-to-name { font-size: 14px; font-weight: 600; color: var(--gray-800); }
.doc-to-detail { font-size: 12px; color: var(--gray-500); margin-top: 2px; }

.doc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin-bottom: 16px;
}

.doc-table thead tr { border-bottom: 2px solid var(--gray-800); }

.doc-table th {
  padding: 8px 10px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.doc-table th.right,
.doc-table td.right { text-align: right; }

.doc-table td {
  padding: 10px 10px;
  border-bottom: 1px solid var(--gray-100);
  color: var(--gray-700);
  vertical-align: top;
}

.doc-table tfoot td {
  border-top: 2px solid var(--gray-800);
  border-bottom: none;
  padding-top: 12px;
  font-weight: 700;
  font-size: 16px;
}

.doc-table tfoot .total-label { color: var(--gray-500); font-weight: 600; font-size: 12px; }
.doc-table tfoot .total-amount { color: var(--navy-dark); font-size: 18px; }

.doc-notes {
  background: var(--amber-bg);
  border-left: 3px solid var(--amber);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 10px 14px;
  margin-bottom: 20px;
  font-size: 12px;
  color: var(--gray-700);
}

.doc-notes-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--amber);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 4px;
}

.doc-tnc {
  font-size: 11px;
  color: var(--gray-400);
  border-top: 1px solid var(--gray-200);
  padding-top: 12px;
  line-height: 1.9;
  margin-bottom: 28px;
}

.doc-sig-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 48px;
  font-size: 12px;
  color: var(--gray-500);
}

.sig-box { text-align: center; }
.sig-space { height: 50px; }
.sig-line { border-bottom: 1px solid var(--gray-300); margin-bottom: 4px; }
.sig-name { font-weight: 600; color: var(--gray-700); }
.sig-role { font-size: 11px; color: var(--gray-400); }

/* ===== PRINT ===== */
@media print {
  .sidebar, .topbar, .btn-group, .action-hint { display: none !important; }
  .app { display: block; }
  .main, .content { overflow: visible; height: auto; }
  .pane { display: none !important; }
  #pane-preview { display: block !important; }
  #doc-preview { border: none; box-shadow: none; }
  body { background: #fff; font-size: 12px; }
  .doc-topbar { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
