/* ── Variables ── */
:root {
  --primary:       #4f46e5;
  --primary-dark:  #4338ca;
  --primary-light: #e0e7ff;
  --success:       #059669;
  --success-light: #d1fae5;
  --warning:       #d97706;
  --warning-light: #fef3c7;
  --danger:        #dc2626;
  --danger-light:  #fee2e2;
  --bg:            #f1f5f9;
  --card:          #ffffff;
  --text:          #0f172a;
  --text-muted:    #64748b;
  --border:        #e2e8f0;
  --radius:        10px;
  --shadow:        0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --shadow-md:     0 4px 12px rgba(0,0,0,.08);
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: system-ui, -apple-system, 'Segoe UI', sans-serif; font-size: 14px; color: var(--text); background: var(--bg); line-height: 1.5; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button { cursor: pointer; font-family: inherit; font-size: 14px; }
input, textarea, select { font-family: inherit; font-size: 14px; }
label { display: block; font-weight: 500; margin-bottom: 5px; color: var(--text); }

/* ── Navbar ── */
.navbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; height: 56px;
  background: #fff; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
}
.nav-brand {
  display: flex; align-items: center; gap: 8px;
  font-weight: 700; font-size: 16px; color: var(--text); text-decoration: none;
}
.nav-brand svg { color: var(--primary); }
.nav-links { display: flex; align-items: center; gap: 6px; }
.nav-link { padding: 5px 12px; border-radius: 6px; color: var(--text-muted); font-weight: 500; transition: background .15s, color .15s; }
.nav-link:hover { background: var(--bg); color: var(--text); text-decoration: none; }
.nav-link.active { color: var(--primary); background: var(--primary-light); }
.nav-sep { width: 1px; height: 20px; background: var(--border); margin: 0 6px; }
.nav-user { font-size: 13px; color: var(--text-muted); padding: 0 4px; }
.btn-logout {
  background: none; border: 1px solid var(--border); color: var(--text-muted);
  padding: 5px 12px; border-radius: 6px; font-size: 13px; transition: all .15s;
}
.btn-logout:hover { border-color: var(--danger); color: var(--danger); background: var(--danger-light); }

/* ── Container ── */
.container { max-width: 1100px; margin: 0 auto; padding: 28px 20px; }

/* ── Page header ── */
.page-header { margin-bottom: 24px; }
.page-header h2 { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.page-header p { color: var(--text-muted); }

/* ── App grid ── */
.app-grid {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 20px;
  align-items: start;
}
@media (max-width: 740px) { .app-grid { grid-template-columns: 1fr; } }

/* ── Card ── */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.card-header h3 { font-size: 15px; font-weight: 700; }

/* ── Form elements ── */
.form-group { margin-bottom: 14px; }
.hint { font-size: 12px; color: var(--text-muted); font-weight: 400; }

input[type="text"],
input[type="email"],
input[type="password"],
textarea {
  width: 100%; padding: 9px 12px;
  border: 1px solid var(--border); border-radius: 7px;
  background: #fff; color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79,70,229,.12);
}
textarea { resize: vertical; min-height: 80px; }

.char-count { text-align: right; font-size: 12px; color: var(--text-muted); margin-top: 3px; }

/* ── File drop zone ── */
.file-drop {
  border: 2px dashed var(--border); border-radius: 8px;
  padding: 20px 16px; text-align: center; cursor: pointer;
  transition: border-color .15s, background .15s;
  color: var(--text-muted);
}
.file-drop:hover, .file-drop.drag-over {
  border-color: var(--primary); background: var(--primary-light);
  color: var(--primary);
}
.file-drop svg { margin-bottom: 8px; opacity: .6; }
.file-drop p { font-size: 13px; margin: 2px 0; }
.file-drop .link { color: var(--primary); cursor: pointer; text-decoration: underline; }

.file-badge {
  display: flex; align-items: center; gap: 8px;
  margin-top: 8px; padding: 7px 10px;
  background: var(--primary-light); border-radius: 6px;
  font-size: 13px; color: var(--primary); font-weight: 500;
}
.file-badge svg { flex-shrink: 0; }
.file-badge span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clear-btn {
  background: none; border: none; color: var(--primary); font-size: 14px;
  padding: 0 2px; line-height: 1; opacity: .7;
}
.clear-btn:hover { opacity: 1; }

/* ── Templates list ── */
.templates-list { display: flex; flex-direction: column; gap: 6px; }
.template-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 11px; border-radius: 7px; border: 1.5px solid var(--border);
  cursor: pointer; transition: all .15s; background: #fff;
}
.template-item:hover { border-color: var(--primary); background: var(--primary-light); }
.template-item.selected { border-color: var(--primary); background: var(--primary-light); }
.template-item-icon { width: 28px; height: 28px; background: var(--primary-light); border-radius: 6px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.template-item-icon svg { color: var(--primary); }
.template-item-body { flex: 1; min-width: 0; }
.template-item-name { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.template-item-meta { font-size: 11px; color: var(--text-muted); }
.badge-ready { display: inline-block; font-size: 10px; padding: 1px 5px; border-radius: 4px; background: var(--success-light); color: var(--success); font-weight: 600; }
.badge-pending { display: inline-block; font-size: 10px; padding: 1px 5px; border-radius: 4px; background: var(--warning-light); color: var(--warning); font-weight: 600; }
.template-del { background: none; border: none; color: var(--text-muted); font-size: 14px; opacity: .5; padding: 2px 4px; }
.template-del:hover { opacity: 1; color: var(--danger); }

/* ── Upload form ── */
.upload-form {
  border: 1px solid var(--border); border-radius: 8px;
  padding: 14px; margin-bottom: 14px; background: var(--bg);
}
.btn-row { display: flex; gap: 8px; }

/* ── Buttons ── */
.btn-primary {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 18px; border: none; border-radius: 7px;
  background: var(--primary); color: #fff; font-weight: 600;
  transition: background .15s, transform .1s; cursor: pointer;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:active { transform: scale(.98); }
.btn-primary:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary.btn-block { width: 100%; justify-content: center; padding: 11px; font-size: 15px; }
.btn-primary.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-convert { margin-top: 4px; }

.btn-outline {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border: 1.5px solid var(--border); border-radius: 7px;
  background: #fff; color: var(--text); font-weight: 500;
  transition: all .15s;
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-light); text-decoration: none; }
.btn-outline.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-outline.btn-xs { padding: 3px 8px; font-size: 12px; }

.btn-ghost { background: none; border: none; color: var(--text-muted); padding: 7px 12px; border-radius: 7px; font-weight: 500; }
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-ghost.btn-sm { padding: 5px 10px; font-size: 13px; }

.btn-success {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border: none; border-radius: 7px;
  background: var(--success); color: #fff; font-weight: 600; font-size: 13px;
  transition: opacity .15s; cursor: pointer; text-decoration: none;
}
.btn-success:hover { opacity: .88; text-decoration: none; }

/* ── Result cards ── */
.result-card {
  display: flex; align-items: center; gap: 12px;
  margin-top: 14px; padding: 14px 16px; border-radius: 9px;
}
.result-ok { background: var(--success-light); color: var(--success); }
.result-err { background: var(--danger-light); color: var(--danger); }
.result-icon { width: 36px; height: 36px; border-radius: 50%; background: rgba(0,0,0,.08); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.result-body { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.result-body strong { font-size: 14px; }
.result-body span { font-size: 12px; }

/* ── Alerts ── */
.alert { padding: 9px 12px; border-radius: 7px; font-size: 13px; margin-top: 10px; }
.alert-error { background: var(--danger-light); color: var(--danger); border: 1px solid #fca5a5; }
.alert-success { background: var(--success-light); color: var(--success); border: 1px solid #6ee7b7; }
.alert-warning { background: var(--warning-light); color: var(--warning); border: 1px solid #fcd34d; }

/* ── Empty state ── */
.empty-state {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 32px 16px; color: var(--text-muted); text-align: center;
}
.empty-state svg { opacity: .3; }
.empty-state p { font-size: 13px; line-height: 1.6; }

/* ── Loading ── */
.loading-row { display: flex; align-items: center; gap: 8px; padding: 16px; color: var(--text-muted); font-size: 13px; }
.spinner {
  width: 16px; height: 16px; border: 2px solid var(--border);
  border-top-color: var(--primary); border-radius: 50%;
  animation: spin .7s linear infinite; flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Table ── */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
  text-align: left; padding: 9px 12px;
  border-bottom: 2px solid var(--border);
  font-weight: 600; color: var(--text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em;
}
.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg); }
.nowrap { white-space: nowrap; }
.instr-cell { max-width: 200px; }

/* ── Badges ── */
.badge { display: inline-block; font-size: 11px; padding: 2px 7px; border-radius: 5px; font-weight: 600; }
.badge-ok   { background: var(--success-light); color: var(--success); }
.badge-err  { background: var(--danger-light);  color: var(--danger); }
.badge-warn { background: var(--warning-light); color: var(--warning); }
.badge-info { background: var(--primary-light); color: var(--primary); }

/* ── Auth pages ── */
.auth-body { background: linear-gradient(135deg, #eef2ff 0%, #f0fdf4 100%); min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.auth-wrap { width: 100%; max-width: 400px; padding: 20px; }
.auth-card { background: #fff; border-radius: 14px; box-shadow: var(--shadow-md); padding: 36px 32px; }
.auth-header { text-align: center; margin-bottom: 28px; }
.auth-header svg { color: var(--primary); margin-bottom: 10px; }
.auth-header h1 { font-size: 22px; font-weight: 800; color: var(--text); margin-bottom: 4px; }
.auth-header p { color: var(--text-muted); font-size: 13px; }
.auth-footer { margin-top: 20px; text-align: center; font-size: 13px; color: var(--text-muted); }
.btn-block { width: 100%; justify-content: center; margin-top: 4px; }

/* ── Utility ── */
.hidden { display: none !important; }
