:root {
  --bg: #f3f6fb;
  --panel: #ffffff;
  --text: #172033;
  --muted: #667085;
  --line: #e4e8f0;
  --blue: #1d4ed8;
  --blue-dark: #173fa8;
  --red: #dc2626;
  --green: #16a34a;
  --shadow: 0 16px 40px rgba(15, 23, 42, .08);
  --radius: 18px;
}

* { box-sizing: border-box; }
body { margin: 0; font-family: Inter, Arial, Helvetica, sans-serif; color: var(--text); background: var(--bg); }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at top left, #dceafe, transparent 34%), var(--bg); }
.login-card { width: 100%; max-width: 420px; background: #fff; border-radius: 24px; box-shadow: var(--shadow); padding: 34px; border: 1px solid var(--line); }
.login-card h1 { margin: 18px 0 8px; font-size: 28px; }
.login-card p { margin: 0 0 24px; color: var(--muted); line-height: 1.45; }
.brand-mark { width: 58px; height: 58px; border-radius: 18px; background: linear-gradient(135deg, var(--red), var(--blue) 55%, var(--green)); color: #fff; display: grid; place-items: center; font-weight: 900; letter-spacing: -.04em; }
.brand-mark.small { width: 42px; height: 42px; border-radius: 14px; font-size: 15px; }

.app { min-height: 100vh; display: grid; grid-template-columns: 260px 1fr; }
.sidebar { background: #101828; color: #fff; padding: 22px; display: flex; flex-direction: column; gap: 22px; position: sticky; top: 0; height: 100vh; }
.side-brand { display: flex; align-items: center; gap: 12px; padding-bottom: 18px; border-bottom: 1px solid rgba(255,255,255,.13); }
.side-brand strong { display: block; }
.side-brand span { display: block; color: #b8c0ce; font-size: 13px; margin-top: 2px; }
nav { display: grid; gap: 10px; }
.nav-btn { border: 0; border-radius: 14px; padding: 12px 14px; background: transparent; color: #d5d9e2; text-align: left; }
.nav-btn:hover, .nav-btn.active { background: rgba(255,255,255,.1); color: #fff; }
.logout { margin-top: auto; color: #fff; border-color: rgba(255,255,255,.2); }

.content { padding: 28px; min-width: 0; }
.top-header { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 20px; }
.top-header h1 { margin: 0; font-size: 28px; }
.top-header p { margin: 6px 0 0; color: var(--muted); }
.header-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.view { display: none; }
.view.active { display: block; }
.grid { display: grid; gap: 18px; }
.grid.two { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.bottom-grid { align-items: start; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 18px; }
.panel-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.panel-title h2 { margin: 0; font-size: 18px; }
.panel-title p { margin: 5px 0 0; color: var(--muted); font-size: 14px; }
.inline-title { align-items: flex-start; }

.form-grid { display: grid; gap: 14px; }
.form-grid.two { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
label { display: grid; gap: 7px; color: #344054; font-weight: 700; font-size: 13px; margin-bottom: 14px; }
input, textarea { width: 100%; border: 1px solid #d0d5dd; border-radius: 12px; padding: 11px 12px; background: #fff; color: var(--text); outline: none; }
input:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 4px rgba(29,78,216,.1); }
textarea { resize: vertical; min-height: 48px; }

button { border: 1px solid transparent; border-radius: 12px; padding: 11px 14px; font-weight: 800; transition: .15s ease; }
button:disabled { opacity: .55; cursor: not-allowed; }
.primary { background: var(--blue); color: #fff; }
.primary:hover:not(:disabled) { background: var(--blue-dark); }
.secondary { background: #eaf1ff; color: var(--blue); border-color: #c8d8ff; }
.secondary:hover:not(:disabled) { background: #dbe8ff; }
.ghost { background: #fff; color: #344054; border-color: var(--line); }
.ghost:hover:not(:disabled) { background: #f8fafc; }
.danger { background: #fff1f1; color: var(--red); border-color: #ffd0d0; }
.full { width: 100%; margin-top: 10px; }
.action-hint { margin-top: 10px; border: 1px solid #fed7aa; background: #fff7ed; color: #9a3412; border-radius: 12px; padding: 10px 12px; font-size: 13px; font-weight: 800; line-height: 1.35; }

.link-importer { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center; }
.table-wrap { overflow-x: auto; margin-top: 16px; border: 1px solid var(--line); border-radius: 16px; }
table { width: 100%; border-collapse: collapse; min-width: 850px; }
th { text-align: left; font-size: 12px; color: #475467; background: #f8fafc; padding: 12px; border-bottom: 1px solid var(--line); }
td { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
.items-table .img-cell { width: 180px; }
.item-preview { width: 78px; height: 78px; object-fit: contain; border: 1px solid var(--line); border-radius: 12px; background: #fff; margin-bottom: 8px; display: block; }
.item-image, .item-url { font-size: 12px; padding: 8px 10px; margin-bottom: 8px; }
.item-title { font-weight: 700; margin-bottom: 8px; }
.item-description { font-size: 12px; }
.item-qty { width: 86px; }
.item-price { width: 120px; }
.item-total { font-weight: 900; white-space: nowrap; vertical-align: middle; }
.remove-item { width: 36px; height: 36px; padding: 0; font-size: 22px; line-height: 1; }

.totals-panel { position: sticky; top: 18px; }
.total-line { display: flex; align-items: center; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--line); }
.total-line.grand { margin-top: 8px; border: 0; background: #101828; color: #fff; padding: 16px; border-radius: 14px; font-size: 20px; }

.badge { background: #fff7e6; color: #a15c00; border: 1px solid #ffd999; border-radius: 999px; padding: 6px 10px; font-size: 12px; font-weight: 800; }
.message, .toast { border-radius: 14px; padding: 12px 14px; margin-top: 12px; font-weight: 700; }
.error { background: #fff1f1; color: #b42318; border: 1px solid #ffd0d0; }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 20; background: #101828; color: #fff; box-shadow: var(--shadow); }

.history-list { display: grid; gap: 12px; }
.history-card { border: 1px solid var(--line); border-radius: 16px; padding: 14px; display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; }
.history-card h3 { margin: 0 0 5px; font-size: 16px; }
.history-card p { margin: 3px 0; color: var(--muted); font-size: 13px; }
.history-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.search { max-width: 340px; }
.empty-state { color: var(--muted); padding: 22px; text-align: center; background: #f8fafc; border-radius: 14px; }

.settings-layout { display: grid; grid-template-columns: 260px 1fr; gap: 18px; align-items: start; }
.logo-form { border: 1px dashed #cbd5e1; border-radius: 16px; padding: 14px; background: #f8fafc; }
.logo-preview { margin-top: 12px; min-height: 100px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 16px; background: #fff; color: var(--muted); padding: 12px; }
.logo-preview img { max-width: 210px; max-height: 92px; object-fit: contain; }

@media (max-width: 980px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; }
  nav { grid-template-columns: repeat(3, 1fr); }
  .logout { margin-top: 0; }
  .top-header, .grid.two, .form-grid.two, .settings-layout { grid-template-columns: 1fr; display: grid; }
  .top-header { align-items: stretch; }
  .header-actions { justify-content: stretch; }
  .header-actions button { flex: 1; }
  .link-importer { grid-template-columns: 1fr; }
  .totals-panel { position: static; }
}

@media (max-width: 620px) {
  .content { padding: 16px; }
  .panel { padding: 16px; border-radius: 16px; }
  nav { grid-template-columns: 1fr; }
  .history-card { grid-template-columns: 1fr; }
  .history-actions { justify-content: flex-start; }
}
