:root {
  --bg: #f4f5fb;
  --card: #ffffff;
  --text: #1f2430;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --success: #16a34a;
  --danger: #dc2626;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 4px 16px rgba(16, 24, 40, 0.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

.hidden { display: none !important; }

/* ===== Topbar ===== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { font-size: 19px; font-weight: 700; }
.brand-icon { margin-right: 6px; }
.brand-web { color: var(--primary); }
.topbar-right { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.user-chip {
  background: #eef2ff;
  color: var(--primary-dark);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
}
.btn-logout {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--muted);
  padding: 6px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
}
.btn-logout:hover { color: var(--danger); border-color: var(--danger); }
.btn-google {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  background: #fff;
  color: #3c4043;
  padding: 6px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
}
.btn-google:hover { border-color: #dadce0; background: #f8f9fa; }
.btn-google .g { font-weight: 700; color: #4285f4; }
.btn-google .g-sber { color: #21a038; }
.admin-badge {
  background: #fef3c7;
  color: #92400e;
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 11px;
  font-weight: 700;
  margin-left: 6px;
}
.pro-badge {
  background: #dcfce7;
  color: #166534;
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 11px;
  font-weight: 700;
  margin-left: 6px;
}

/* ===== Auth ===== */
.auth-view {
  min-height: calc(100vh - 60px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
}
.auth-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 36px;
  width: 100%;
  max-width: 420px;
}
.auth-title { margin: 0 0 4px; font-size: 24px; }
.auth-subtitle { margin: 0 0 22px; color: var(--muted); font-size: 14px; }
.auth-tabs { display: flex; gap: 6px; margin-bottom: 20px; }
.auth-tab {
  flex: 1;
  padding: 9px;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
}
.auth-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.field input {
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  color: var(--text);
}
.field input:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: transparent; }
.form-error { color: var(--danger); font-size: 13px; margin: 0; min-height: 18px; }

/* ===== Layout ===== */
.app-view { max-width: 880px; margin: 0 auto; padding: 24px 16px 60px; display: flex; flex-direction: column; gap: 18px; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; }
.card-title { margin: 0 0 16px; font-size: 17px; display: flex; align-items: center; gap: 10px; }
.step {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
}

/* ===== Usage bar ===== */
.usage-bar {
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  color: #fff;
  border-radius: var(--radius);
  padding: 12px 18px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow);
}

/* ===== Dropzone ===== */
.dropzone {
  border: 2px dashed #c7cbe0;
  border-radius: 12px;
  padding: 26px;
  text-align: center;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  background: #fafbff;
}
.dropzone:hover, .dropzone.dragover { border-color: var(--primary); background: #eef2ff; }
.dz-icon { font-size: 30px; }
.dz-text { color: var(--muted); margin-top: 6px; }
.dz-link { color: var(--primary); font-weight: 600; }
.file-chip {
  margin-top: 12px;
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  color: #065f46;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 14px;
}

/* ===== Rows / inputs ===== */
.row { margin-top: 16px; }
.row.inline { display: flex; align-items: center; gap: 10px; }
.row.inline label { color: var(--text); font-weight: 500; }
.row.inline input[type="number"] {
  width: 70px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
}
.row.inline.grow input { width: 100%; padding: 10px 12px; }
.sub-label { margin-top: 18px; font-weight: 600; font-size: 14px; }
.hint { margin-top: 8px; color: var(--muted); font-size: 12.5px; }

/* ===== Colors ===== */
.colors { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.color-check { display: none; }
.color-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  font-size: 13px;
  user-select: none;
  background: #fff;
  transition: background 0.12s, border-color 0.12s;
}
.color-pill .dot { width: 14px; height: 14px; border-radius: 50%; border: 1px solid rgba(0,0,0,0.15); }
.color-pill.checked { background: #eef2ff; border-color: var(--primary); color: var(--primary-dark); font-weight: 600; }

/* ===== Mask buttons ===== */
.mask-buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.mask-btn {
  padding: 7px 12px;
  border: 1px solid #bbf7d0;
  background: #f0fdf4;
  color: #166534;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}
.mask-btn:hover { background: #dcfce7; }
.mask-btn.copied { background: #dcfce7; border-color: var(--success); }

/* ===== Templates ===== */
.tpl-list { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }
.tpl-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
}
.tpl-name {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  overflow-wrap: anywhere;
}
.tpl-item .tpl-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 6px;
  background: #f3f4f6;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.tpl-item .tpl-pdf { background: #fee2e2; color: #b91c1c; }

/* ===== Radios ===== */
.radios { display: flex; flex-wrap: wrap; gap: 12px; }
.radio { display: flex; align-items: center; gap: 7px; cursor: pointer; font-size: 14px; }
.radio input { accent-color: var(--primary); width: 16px; height: 16px; }

/* ===== Actions ===== */
.actions { display: flex; gap: 10px; flex-wrap: wrap; }
.btn {
  padding: 12px 22px;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: filter 0.12s, opacity 0.12s;
}
.btn:hover { filter: brightness(0.95); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-outline { background: #fff; color: var(--primary); border: 1px solid var(--primary); }
.btn-block { width: 100%; }

/* ===== Progress ===== */
.progress-track {
  height: 12px;
  background: #eef0f6;
  border-radius: 999px;
  overflow: hidden;
  margin-top: 18px;
}
.progress-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #4f46e5, #16a34a);
  border-radius: 999px;
  transition: width 0.3s ease;
}
.progress-text { text-align: right; font-size: 13px; color: var(--muted); margin-top: 5px; }

/* ===== Log ===== */
.log {
  margin-top: 14px;
  background: #0f172a;
  color: #d1d5db;
  padding: 14px;
  border-radius: 10px;
  font-family: "Consolas", "Menlo", monospace;
  font-size: 12.5px;
  max-height: 260px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #1f2430;
  color: #fff;
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 50;
  max-width: 90%;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--danger); }

/* ===== Template item actions ===== */
.tpl-actions { display: flex; gap: 6px; margin-left: auto; flex-shrink: 0; }
.tpl-actions .btn { padding: 5px 10px; font-size: 12.5px; border-radius: 7px; font-weight: 600; }

/* ===== Data preview teaser ===== */
.preview-meta { color: var(--muted); font-size: 12.5px; }
.sheet-teaser {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fafbff;
}
.sheet-teaser .btn {
  margin-left: auto;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 8px;
  white-space: nowrap;
}

/* ===== Full-screen sheet panel (Google Sheets-like) ===== */
body.no-scroll { overflow: hidden; }
.sheet-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.55);
}
.sheet-panel {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  max-width: 1700px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.35);
  overflow: hidden;
}
.sheet-head {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sheet-title { font-weight: 600; font-size: 15px; }
.sheet-meta { color: var(--muted); font-size: 12.5px; margin-left: auto; }
.sheet-close {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--muted);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  flex-shrink: 0;
}
.sheet-close:hover { color: var(--danger); border-color: var(--danger); }
.sheet-popout {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--primary);
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}
.sheet-popout:hover { border-color: var(--primary); background: #eef2ff; }
.sheet-scroll { flex: 1; overflow: auto; background: #fff; }
.sheet-empty { padding: 16px; }
.sheet-table { border-collapse: separate; border-spacing: 0; font-size: 13px; }
.sheet-table th,
.sheet-table td {
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 6px 12px;
  text-align: left;
  white-space: nowrap;
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  background: #fff;
}
.sheet-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f3f5fb;
  font-weight: 600;
  border-bottom: 1px solid #d8dced;
}
.sheet-table td:first-child,
.sheet-table th:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  background: #f8f9fc;
}
.sheet-table thead th:first-child { z-index: 3; background: #e9edf7; }
.sheet-color-cell { white-space: nowrap; }
.sheet-color-dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.2);
  margin-right: 6px;
  vertical-align: middle;
}
