/* Notion-inspired theme */
:root {
  --bg: #ffffff;
  --text: #37352f;
  --text-secondary: #787774;
  --muted: #f7f6f3;
  --muted-dark: #efefee;
  --border: #e3e2df;
  --accent: #2383e2;
  --accent-hover: #0b6bcb;
  --hover: #f1f1ef;
  --hover-card: #fafaf9;
  --sidebar-bg: #fbfbfa;
  --shadow: rgba(15, 15, 15, 0.1);
  --shadow-sm: rgba(15, 15, 15, 0.05);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, "Apple Color Emoji", sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-size: 14px;
  line-height: 1.5;
}

body.auth-open {
  overflow: hidden;
}

/* Legacy header (admin page) */
header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; background: var(--muted); border-bottom: 1px solid var(--border);
}
h1 { margin: 0; font-weight: 700; font-size: 20px; }

/* Layout */
.layout { display: flex; min-height: 100vh; }
.sidebar-toggle {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 12px 16px;
  border: none;
  border-radius: 0;
  background: var(--muted);
  color: var(--text);
  font-weight: 600;
  font-size: 15px;
}
.sidebar-toggle:hover { background: var(--hover); }
.sidebar-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.sidebar {
  width: 260px;
  border-right: 1px solid var(--border);
  background: var(--sidebar-bg);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.sidebar-header {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 4px;
  margin-bottom: 8px;
}
.workspace {
  font-weight: 600;
  padding: 6px 8px;
  border-radius: 4px;
  font-size: 14px;
  color: var(--text);
  letter-spacing: -0.01em;
}
.nav-title {
  color: var(--text-secondary);
  font-size: 11px;
  padding: 6px 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  margin-top: 8px;
}
.nav-list { display: flex; flex-direction: column; gap: 4px; }
.nav-list .item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 8px 4px 8px;
  border-radius: 4px;
  transition: background 0.12s ease;
  cursor: pointer;
}
.nav-list .item:hover {
  background: var(--hover);
}
.nav-list .item:focus-within {
  background: var(--hover);
}
.nav-list .nav-page {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
  padding: 0;
  background: none;
  border: none;
  color: inherit;
  text-align: left;
  height: auto;
  font: inherit;
}
.nav-list .nav-page:focus-visible {
  outline: none;
}
.nav-list .page-icon {
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}
.nav-list .page-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}
.nav-list .page-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.nav-list .page-meta {
  font-size: 11px;
  color: var(--text-secondary);
}
.nav-list .item-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  padding-right: 4px;
  opacity: 0;
  transition: opacity 0.12s ease;
  flex-shrink: 0;
}
.nav-list .item:hover .item-actions,
.nav-list .item:focus-within .item-actions {
  opacity: 1;
}
.icon-button {
  border: none;
  background: none;
  padding: 4px;
  height: auto;
  font-size: 14px;
  line-height: 1;
  color: var(--text-secondary);
  border-radius: 4px;
  transition: background 0.12s ease, color 0.12s ease;
}
.icon-button:hover {
  background: var(--hover);
  color: var(--text);
}
.nav-empty {
  font-size: 13px;
  color: var(--text-secondary);
  padding: 24px 12px;
  text-align: center;
  line-height: 1.5;
}

.page {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  position: relative;
}

.page-top-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
  background: rgba(255, 255, 255, 0.95);
}

.top-bar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.support-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  text-decoration: none;
  border-radius: 4px;
  transition: background 0.12s ease;
  background: rgba(15, 15, 15, 0.02);
  border: 1px solid var(--border);
}

.support-link:hover {
  background: var(--hover);
}

.page-inner {
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
  padding: 48px 96px 96px;
}

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 32px;
  gap: 24px;
}

.page-header h1 {
  font-size: 40px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
  margin: 0;
}

.page-header .actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--muted);
  border: 1px solid var(--border);
  font-size: 13px;
  transition: background 0.12s ease;
}
.user-chip:hover {
  background: var(--muted-dark);
}
.user-chip #user-name {
  font-weight: 500;
  color: var(--text);
}

.auth-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(17, 24, 39, 0.45);
  backdrop-filter: blur(2px);
  z-index: 999;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: #fff;
  border-radius: 12px;
  padding: 32px;
  box-shadow: 0 20px 60px rgba(15, 15, 15, 0.12), 0 0 0 1px var(--border);
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.auth-card h2 {
  margin: 0;
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}

.auth-subtitle {
  margin: 0;
  color: var(--text-secondary);
  font-size: 15px;
  line-height: 1.5;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: 8px;
}

.auth-form label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}

.auth-form input {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 15px;
  background: #fff;
  color: var(--text);
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.auth-form input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.auth-error {
  min-height: 18px;
  color: #dc2626;
  font-size: 13px;
  margin: 0;
}

.auth-switch {
  font-size: 14px;
  color: var(--text-secondary);
  margin: 0;
  text-align: center;
}

.auth-switch .link {
  border: none;
  background: none;
  color: var(--accent);
  padding: 0;
  font-size: inherit;
  cursor: pointer;
  height: auto;
  font-weight: 500;
  transition: color 0.12s ease;
}

.auth-switch .link:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

.auth-overlay[hidden] {
  display: none;
}

/* Buttons */
button {
  cursor: pointer;
  border-radius: 4px;
  height: 32px;
  padding: 0 12px;
  font-weight: 500;
  font-size: 14px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  transition: background 0.12s ease, border-color 0.12s ease, transform 0.08s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
button:hover {
  background: var(--hover-card);
}
button:active {
  transform: scale(0.98);
}
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 500;
}
button.primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}
button.ghost {
  background: rgba(15, 15, 15, 0.02);
  border-color: transparent;
  color: var(--text);
}
button.ghost:hover {
  background: var(--hover);
}
button.small {
  height: 28px;
  padding: 0 10px;
  font-size: 13px;
}
button.listening {
  border-color: var(--accent);
  background: rgba(35, 131, 226, 0.08);
  box-shadow: 0 0 0 1px var(--accent) inset;
}

/* Blocks */
.block-title {
  font-weight: 600;
  font-size: 13px;
  color: var(--text-secondary);
  margin: 32px 0 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.block-title:first-child {
  margin-top: 0;
}
.subtle {
  color: var(--text-secondary);
  font-size: 12px;
  margin: 8px 0 4px;
  font-weight: 500;
}
.ingest {
  margin-top: 0;
}

.ingest-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.ingest textarea {
  width: 100%;
  min-height: 140px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fff;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  resize: vertical;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
.ingest textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}
.ingest textarea::placeholder {
  color: var(--text-secondary);
  opacity: 0.6;
}
.ingest-buttons {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
.hint {
  color: var(--text-secondary);
  font-size: 12px;
  margin-top: 8px;
}

.quote-form {
  margin-top: 48px;
  animation: slideDown 0.4s ease-out;
  transform-origin: top;
}

.quote-form[hidden] {
  display: none;
}

.quote-header {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-bottom: 24px;
}

.quote-logo {
  max-width: 120px;
  max-height: 80px;
  object-fit: contain;
}

.quote-logo[hidden] {
  display: none;
}

.quote-title {
  display: none;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-top: 12px;
}
.grid input,
.grid textarea,
.meta input,
.notes textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fff;
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
.grid input:focus,
.grid textarea:focus,
.meta input:focus,
.notes textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.grid input[readonly],
.grid textarea[readonly] {
  background: var(--muted);
  cursor: not-allowed;
  opacity: 0.7;
}
.grid textarea,
.notes textarea {
  min-height: 80px;
  resize: vertical;
  line-height: 1.5;
}

.meta {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 20px 0;
}
.meta label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}

/* Table */
table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
thead th {
  background: var(--muted);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
th, td {
  border-bottom: 1px solid var(--border);
  padding: 12px;
  text-align: left;
}
tbody tr {
  transition: background 0.12s ease;
}
tbody tr:hover {
  background: var(--hover-card);
}
tbody tr:last-child td {
  border-bottom: none;
}
td input,
td textarea {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fff;
  font-size: 14px;
  color: var(--text);
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
td input:focus,
td textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}
td textarea.desc {
  min-width: 260px;
  width: 100%;
  min-height: 32px;
  resize: none;
  overflow: hidden;
  font-family: inherit;
  line-height: 1.5;
}

td .desc-print {
  display: none;
}
td input.qty {
  width: 70px;
  text-align: right;
}
td input.pu {
  width: 90px;
  text-align: right;
}
td .rm {
  height: 28px;
  padding: 0 8px;
  font-size: 13px;
}
.table-actions {
  margin-top: 12px;
}
.table-container {
  margin-top: 12px;
  overflow-x: auto;
  border-radius: 6px;
}
.table-container table {
  min-width: 620px;
}

.totals {
  margin: 24px 0;
  display: grid;
  gap: 8px;
  width: 100%;
  max-width: 320px;
  padding: 16px;
  background: var(--muted);
  border-radius: 6px;
  font-size: 14px;
}
.totals div {
  display: flex;
  justify-content: space-between;
  color: var(--text);
}
.totals .grand {
  font-weight: 600;
  font-size: 16px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}

.notes {
  margin-top: 24px;
}

.save {
  margin: 32px 0 16px;
}
.save button {
  padding: 0 20px;
  height: 36px;
  font-size: 15px;
  font-weight: 500;
}

/* Responsive */
@media (max-width: 960px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--border); }
  .page-top-bar { padding: 12px 20px; }
  .page-inner { padding: 32px 40px; }
  .page-header { flex-wrap: wrap; gap: 12px; }
  .page-header h1 { font-size: 32px; }
  .grid { grid-template-columns: 1fr; }
  .meta { grid-template-columns: 1fr 1fr; }
  .totals { max-width: 100%; }
}

@media (max-width: 720px) {
  .sidebar-toggle { display: flex; position: sticky; top: 0; z-index: 5; }
  .layout { flex-direction: column; min-height: unset; }
  .sidebar {
    display: none;
    width: 100%;
    border-bottom: none;
    border-radius: 0 0 12px 12px;
    box-shadow: 0 12px 24px -20px var(--shadow);
    padding: 16px;
  }
  .sidebar.open { display: block; animation: fadeDown 0.18s ease-out; }
  .nav-list .item { flex-direction: column; align-items: stretch; justify-content: flex-start; gap: 6px; padding: 10px; }
  .nav-list .item-actions { opacity: 1; justify-content: flex-end; }
  .nav-list .nav-page { gap: 8px; }
  .page-top-bar {
    padding: 10px 16px;
    flex-wrap: wrap;
    gap: 8px;
  }
  .page-inner { padding: 24px 20px; }
  .page-header { flex-direction: column; align-items: flex-start; gap: 12px; }
  .page-header h1 { font-size: 28px; }
  .page-header .actions { width: 100%; justify-content: flex-start; }
  .ingest-header { flex-direction: column; align-items: flex-start; gap: 8px; }
  .ingest textarea { min-height: 140px; }
  .ingest-buttons { flex-wrap: wrap; gap: 10px; }
  .ingest-buttons button { flex: 1 1 calc(50% - 10px); min-width: 140px; }
  .meta { grid-template-columns: 1fr; }
  .meta label { flex-direction: row; align-items: center; gap: 8px; }
  .totals { width: 100%; max-width: 100%; }
  .table-container { margin-top: 16px; -webkit-overflow-scrolling: touch; box-shadow: inset 0 0 0 1px var(--border); }
  .table-container table { min-width: 540px; border: none; }
  table { border-radius: 0; }
  thead th, th, td { font-size: 13px; padding: 10px; }
  .save button { width: 100%; }
}

@media (max-width: 540px) {
  .ingest-buttons button { flex: 1 1 100%; min-width: unset; }
  .page-header h1 { font-size: 24px; }
  .table-actions { display: flex; }
  .table-actions button { flex: 1; }
}

@keyframes fadeDown {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Subscription styles */
.subscription-info {
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.subscription-info:hover {
  filter: brightness(0.96);
}

.subscription-info .info-icon {
  font-size: 13px;
  opacity: 0.6;
  transition: opacity 0.12s ease;
}

.subscription-info:hover .info-icon {
  opacity: 0.9;
}

.subscription-info.free {
  background: #fef3c7;
  color: #92400e;
  border-color: #fde68a;
}

.subscription-info.unlimited {
  background: #d1fae5;
  color: #065f46;
  border-color: #a7f3d0;
}

.subscription-modal {
  max-width: 480px;
}

.subscription-modal h2 {
  margin-bottom: 8px;
}

.subscription-modal-content {
  margin: 20px 0 0;
}

.subscription-stat {
  padding: 20px;
  background: var(--muted);
  border-radius: 8px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
  transition: background 0.12s ease;
}

.subscription-stat:hover {
  background: var(--muted-dark);
}

.subscription-stat-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}

.subscription-stat-value {
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}

.subscription-actions {
  display: flex;
  gap: 12px;
  margin-top: 24px;
  flex-wrap: wrap;
}

.subscription-actions button,
.subscription-actions a {
  flex: 1;
  min-width: 140px;
}

.btn-upgrade {
  background: var(--accent);
  color: white !important;
  padding: 12px 24px;
  border: none;
  border-radius: 6px;
  font-weight: 500;
  font-size: 15px;
  cursor: pointer;
  transition: background 0.12s ease, transform 0.08s ease;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 44px;
}

.btn-upgrade:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.btn-upgrade:active {
  transform: scale(0.98);
}

.btn-cancel {
  background: #ef4444;
  color: white;
  padding: 12px 24px;
  border: none;
  border-radius: 6px;
  font-weight: 500;
  font-size: 15px;
  cursor: pointer;
  transition: background 0.12s ease, transform 0.08s ease;
  height: 44px;
}

.btn-cancel:hover {
  background: #dc2626;
  transform: translateY(-1px);
}

.btn-cancel:active {
  transform: scale(0.98);
}

.subscription-actions .ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 24px;
  border-radius: 6px;
  font-weight: 500;
  font-size: 15px;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
  height: 44px;
}

.subscription-actions .ghost:hover {
  background: var(--hover);
  border-color: var(--text-secondary);
}

.subscription-warning {
  padding: 16px;
  background: #fef3c7;
  border: 1px solid #fde68a;
  border-left: 4px solid #f59e0b;
  border-radius: 6px;
  margin: 16px 0;
  font-size: 14px;
  line-height: 1.5;
  color: #92400e;
}

/* Limit Reached Modal */
.limit-modal {
  max-width: 460px;
  text-align: center;
}

.limit-icon {
  font-size: 64px;
  margin-bottom: 16px;
  animation: bounceIn 0.6s ease-out;
}

@keyframes bounceIn {
  0% {
    opacity: 0;
    transform: scale(0.3);
  }
  50% {
    opacity: 1;
    transform: scale(1.05);
  }
  70% {
    transform: scale(0.9);
  }
  100% {
    transform: scale(1);
  }
}

.limit-modal h2 {
  margin: 0 0 16px;
  font-size: 28px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.02em;
}

.limit-message {
  font-size: 16px;
  line-height: 1.6;
  color: var(--text-secondary);
  margin: 0 0 24px;
}

.limit-message strong {
  color: var(--text);
  font-weight: 600;
}

.limit-benefits {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 28px;
  padding: 20px;
  background: var(--muted);
  border-radius: 8px;
  border: 1px solid var(--border);
}

.limit-benefit {
  font-size: 15px;
  color: var(--text);
  text-align: left;
  font-weight: 500;
}

.limit-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.limit-actions .btn-upgrade,
.limit-actions .ghost {
  width: 100%;
  justify-content: center;
}

/* Logo upload styles */
.logo-upload {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.logo-label {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
  margin-bottom: 8px;
}

.logo-input {
  width: 100%;
  padding: 8px;
  border: 1px dashed var(--border);
  border-radius: 4px;
  background: var(--muted);
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease;
}

.logo-input:hover {
  border-color: var(--accent);
  background: var(--hover);
}

.logo-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.logo-preview {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-preview[hidden] {
  display: none;
}

.logo-preview img {
  max-width: 80px;
  max-height: 80px;
  object-fit: contain;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px;
  background: #fff;
}

.logo-remove {
  padding: 6px 12px;
  height: 28px;
  font-size: 12px;
  background: #ef4444;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.12s ease;
  margin-left: auto;
}

.logo-remove:hover {
  background: #dc2626;
}
