/* ── Reset & Base ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #ffffff;
  --bg-2:      #f5f5f7;
  --bg-3:      #e8e8ed;
  --label:     #1d1d1f;
  --label-2:   #6e6e73;
  --label-3:   #aeaeb2;
  --separator: #d2d2d7;
  --red:       #ff3b30;
  --red-soft:  rgba(255, 59, 48, 0.08);
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --font: -apple-system, "SF Pro Text", "SF Pro Display", BlinkMacSystemFont, system-ui, sans-serif;
}

html { font-size: 16px; }

body {
  font-family: var(--font);
  background: var(--bg-2);
  color: var(--label);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ── Header ──────────────────────────────────────────────────── */
.header {
  background: rgba(255,255,255,0.82);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--separator);
  padding: 0 48px;
  height: 52px;
  display: flex;
  align-items: center;
  gap: 10px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.btn-home {
  display: inline-block;
  padding: 10px 22px;
  background: #0071e3;
  color: #fff;
  font-family: var(--font);
  font-size: 15px;
  font-weight: 500;
  border-radius: 980px;
  text-decoration: none;
  text-align: center;
  transition: background .2s;
  flex-shrink: 0;
  margin-right: 6px;
}

.btn-home:hover  { background: #0077ed; }
.btn-home:active { background: #006edb; }

.header h1 {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -.2px;
  color: var(--label);
}

.header-badge {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .4px;
  color: var(--label-2);
  text-transform: uppercase;
}

/* ── Tabs ────────────────────────────────────────────────────── */
.tabs-bar {
  background: rgba(255,255,255,0.82);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--separator);
  padding: 0 48px;
  display: flex;
  gap: 0;
}

.tab-btn {
  padding: 12px 20px;
  border: none;
  background: transparent;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 400;
  color: var(--label-2);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color .15s;
  -webkit-font-smoothing: antialiased;
}

.tab-btn:hover { color: var(--label); }
.tab-btn.active {
  color: var(--label);
  font-weight: 500;
  border-bottom-color: var(--label);
}

/* ── Layout ──────────────────────────────────────────────────── */
.container { max-width: 860px; margin: 0 auto; padding: 48px 48px 80px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Section blocks ──────────────────────────────────────────── */
.files-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
  align-items: start;
}

.files-grid .card { margin-bottom: 0; }

.card {
  background: var(--bg);
  border-radius: var(--radius-lg);
  padding: 28px 32px;
  margin-bottom: 16px;
}

.card-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .6px;
  text-transform: uppercase;
  color: var(--label-2);
  margin-bottom: 18px;
}

/* ── Drop zone ───────────────────────────────────────────────── */
.drop-zone {
  border: 1.5px dashed var(--separator);
  border-radius: var(--radius-md);
  padding: 36px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s, background .2s;
  min-height: 210px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.drop-zone:hover,
.drop-zone.drag-over {
  border-color: var(--label-3);
  background: var(--bg-2);
}

.dz-icon {
  display: block;
  font-size: 28px;
  margin-bottom: 10px;
  opacity: .7;
}

.drop-zone p {
  font-size: 14px;
  color: var(--label-2);
  line-height: 1.55;
}

.drop-zone strong { color: var(--label); font-weight: 500; }

.btn-choose {
  display: inline-block;
  margin-top: 14px;
  padding: 8px 18px;
  background: var(--bg-2);
  color: var(--label);
  border: none;
  border-radius: 980px;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s;
  -webkit-font-smoothing: antialiased;
}

.btn-choose:hover { background: var(--bg-3); }

/* ── File list ───────────────────────────────────────────────── */
.file-list { margin-top: 12px; display: flex; flex-direction: column; gap: 1px; }

.file-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  transition: background .12s;
}

.file-item:hover { background: var(--bg-2); }

.fi-icon { font-size: 15px; flex-shrink: 0; opacity: .6; }

.fi-name {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
  color: var(--label);
  overflow-wrap: break-word;
  word-break: break-all;
  min-width: 0;
}

.fi-size {
  font-size: 12px;
  color: var(--label-3);
  white-space: nowrap;
}

.fi-remove {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--label-3);
  font-size: 18px;
  line-height: 1;
  padding: 0;
  flex-shrink: 0;
  transition: color .12s;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
}

.fi-remove:hover { color: var(--red); }

/* ── Coefficient ─────────────────────────────────────────────── */
.coef-row { display: flex; align-items: center; gap: 16px; }

.coef-input {
  width: 120px;
  padding: 10px 14px;
  background: var(--bg-2);
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 17px;
  font-weight: 500;
  color: var(--label);
  -webkit-font-smoothing: antialiased;
  appearance: none;
  -moz-appearance: textfield;
  transition: background .15s;
}

.coef-input::-webkit-outer-spin-button,
.coef-input::-webkit-inner-spin-button { -webkit-appearance: none; }

.coef-input:focus {
  outline: none;
  background: var(--bg-3);
}

.coef-hint {
  font-size: 13px;
  color: var(--label-3);
}

/* ── Calculate button ────────────────────────────────────────── */
.btn-calc {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 13px 32px;
  background: var(--label);
  color: #fff;
  border: none;
  border-radius: 980px;
  font-family: var(--font);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  letter-spacing: -.1px;
  transition: opacity .15s, transform .1s;
  -webkit-font-smoothing: antialiased;
  margin-top: 4px;
}

.btn-calc:hover:not(:disabled) { opacity: .82; }
.btn-calc:active:not(:disabled) { transform: scale(.98); }
.btn-calc:disabled { opacity: .25; cursor: not-allowed; }

/* ── Messages ────────────────────────────────────────────────── */
.msg-box {
  padding: 13px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.5;
  margin-bottom: 16px;
  color: var(--label);
}

.msg-box.error   { background: var(--red-soft); color: var(--red); }
.msg-box.warning { background: rgba(255,179,0,.1); color: #a05700; }
.msg-box.info    { background: var(--bg-2); color: var(--label-2); }
.msg-box.success { background: rgba(52,199,89,.1); color: #1a7a36; }
.msg-box ul { margin: 5px 0 0 16px; }

/* ── Result ──────────────────────────────────────────────────── */
.result-section { margin-top: 8px; }

.result-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 16px;
}

.result-header h2 {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -.3px;
}

.result-meta {
  font-size: 13px;
  color: var(--label-3);
  flex-shrink: 0;
}

.result-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
}

.btn-save,
.btn-export {
  padding: 8px 20px;
  border: none;
  border-radius: 980px;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s;
  white-space: nowrap;
  -webkit-font-smoothing: antialiased;
}

.btn-save {
  background: var(--bg-2);
  color: var(--label);
}

.btn-save:hover:not(:disabled) { background: var(--bg-3); }
.btn-save:disabled { opacity: .35; cursor: not-allowed; }

.btn-export {
  background: #e8f4e8;
  color: #1a7a36;
}

.btn-export:hover:not(:disabled) { background: #d4edda; }
.btn-export:disabled { opacity: .35; cursor: not-allowed; }

/* ── Table ───────────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-md);
  background: var(--bg);
}

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

th {
  background: var(--bg);
  padding: 10px 16px;
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .3px;
  text-transform: uppercase;
  color: var(--label-2);
  white-space: nowrap;
  border-bottom: 1px solid var(--separator);
  position: sticky;
  top: 0;
  z-index: 2;
}

th.col-article {
  text-align: left;
  position: sticky;
  left: 0;
  z-index: 3;
}

td {
  padding: 10px 16px;
  text-align: center;
  white-space: nowrap;
  color: var(--label);
  border-bottom: 1px solid var(--bg-2);
}

tr:last-child td { border-bottom: none; }

td.col-article {
  text-align: left;
  font-weight: 500;
  background: var(--bg);
  position: sticky;
  left: 0;
  z-index: 1;
}

th.col-nom { text-align: left; min-width: 150px; }
td.col-nom  { text-align: left; color: var(--label-2); font-size: 12px; }

td.deficit {
  background: #ffe58f;
  color: var(--red);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

td.profit {
  color: #1a7a36;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

tr.total-row td {
  background: var(--bg-2);
  font-weight: 600;
  border-top: 1px solid var(--separator);
  border-bottom: none;
  color: var(--label);
}

tr.total-row td.col-article { background: var(--bg-2); }

td.col-total,
th.col-total {
  background: var(--bg-2);
  font-weight: 600;
  border-left: 1px solid var(--separator);
}

td.col-total.deficit { color: var(--red); }

tr.total-row td.col-total { background: var(--bg-3); }

/* ── Archive ─────────────────────────────────────────────────── */
.archive-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.archive-header h2 {
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -.4px;
}

.archive-count {
  font-size: 13px;
  color: var(--label-3);
}

.archive-list { display: flex; flex-direction: column; gap: 1px; }

.archive-item {
  background: var(--bg);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: 8px;
}

.archive-item-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 24px;
  cursor: pointer;
  transition: background .12s;
  user-select: none;
}

.archive-item-header:hover { background: var(--bg-2); }

.ai-date {
  flex: 1;
  font-size: 14px;
  font-weight: 500;
  color: var(--label);
}

.ai-meta {
  font-size: 13px;
  color: var(--label-3);
}

.ai-chevron {
  font-size: 11px;
  color: var(--label-3);
  transition: transform .2s;
  margin-left: 4px;
}

.archive-item.open .ai-chevron { transform: rotate(180deg); }

.btn-export-arch {
  padding: 5px 14px;
  background: #e8f4e8;
  color: #1a7a36;
  border: none;
  border-radius: 980px;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background .12s;
  white-space: nowrap;
  -webkit-font-smoothing: antialiased;
  flex-shrink: 0;
}

.btn-export-arch:hover { background: #d4edda; }

.btn-delete-arch {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--label-3);
  font-size: 20px;
  padding: 0;
  line-height: 1;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: color .12s, background .12s;
  flex-shrink: 0;
}

.btn-delete-arch:hover {
  color: var(--red);
  background: var(--red-soft);
}

.archive-item-body {
  display: none;
  padding: 0 24px 20px;
}

.archive-item.open .archive-item-body { display: block; }

/* ── Modal ───────────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.3);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 100;
  align-items: center;
  justify-content: center;
}

.modal-overlay.show { display: flex; }

.modal {
  background: var(--bg);
  border-radius: var(--radius-lg);
  padding: 32px 32px 28px;
  max-width: 400px;
  width: 90%;
  animation: modal-in .2s ease;
}

@keyframes modal-in {
  from { opacity: 0; transform: scale(.96) translateY(6px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal h3 {
  font-size: 17px;
  font-weight: 600;
  margin-bottom: 8px;
  letter-spacing: -.1px;
}

.modal p {
  font-size: 14px;
  color: var(--label-2);
  line-height: 1.5;
  margin-bottom: 24px;
}

.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }

.btn-cancel {
  padding: 9px 20px;
  background: var(--bg-2);
  color: var(--label);
  border: none;
  border-radius: 980px;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background .12s;
  -webkit-font-smoothing: antialiased;
}

.btn-cancel:hover { background: var(--bg-3); }

.btn-confirm-delete {
  padding: 9px 20px;
  background: var(--red);
  color: #fff;
  border: none;
  border-radius: 980px;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity .12s;
  -webkit-font-smoothing: antialiased;
}

.btn-confirm-delete:hover { opacity: .86; }

/* ── Spinner ─────────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,.35);
  border-top-color: rgba(255,255,255,.9);
  border-radius: 50%;
  animation: spin .65s linear infinite;
  vertical-align: middle;
  margin-right: 7px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Empty state ─────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 72px 20px;
  color: var(--label-3);
}

.es-icon {
  display: block;
  font-size: 40px;
  margin-bottom: 14px;
  opacity: .5;
}

.empty-state p {
  font-size: 14px;
  line-height: 1.55;
  max-width: 280px;
  margin: 0 auto;
}
