/* Design tokens */
:root {
  --bg: #FFFFFF;
  --secondary: #E5E5E5;
  --primary: #FCA311;
  --primary-dark: #DB8C0A;
  --ink: #1A1A1A;
  --ink-soft: #6B6B6B;
  --border: #E5E5E5;
  --error: #C0392B;
  --error-bg: #FBEAE7;
  --success: #2E7D32;
  --radius-card: 20px;
  --radius-field: 10px;
  --font-display: 'Space Grotesk', sans-serif;
  --font-body: 'Inter', sans-serif;
}

/* Reset */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}

.hidden { display: none !important; }

button {
  font-family: var(--font-body);
  cursor: pointer;
}

input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Views */
.view { min-height: 100vh; }

/* Please-wait toast */
.wait-toast {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translate(-50%, -140%);
  background: var(--ink);
  color: #FFFFFF;
  padding: 10px 18px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.22);
  z-index: 999;
  pointer-events: none;
  transition: transform 0.25s ease;
}

.wait-toast.show { transform: translate(-50%, 0); }

.wait-toast-spinner {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #FFFFFF;
  animation: spin 0.7s linear infinite;
}

/* Buttons */
.btn {
  border: none;
  border-radius: 999px;
  padding: 12px 20px;
  font-size: 14px;
  font-weight: 600;
}

.btn-primary { background: var(--primary); color: #1A1200; }
.btn-primary:hover { background: var(--primary-dark); }

.btn-danger { background: transparent; color: var(--error); border: 1px solid var(--error); }
.btn-danger:hover { background: var(--error-bg); }

.btn-link {
  background: none;
  color: var(--ink-soft);
  padding: 8px 4px;
  text-decoration: underline;
  font-size: 14px;
}

.icon-btn {
  background: var(--secondary);
  border: none;
  border-radius: 10px;
  width: 38px;
  height: 38px;
  font-size: 17px;
  line-height: 1;
  color: var(--ink);
}

.icon-btn:disabled { color: #B5B5B5; cursor: not-allowed; }

.btn-primary:disabled { background: #E9C98A; color: #FFFFFF; cursor: not-allowed; }

/* Auth screens (landing / signup / otp / setpin / login / forgot) */
.auth-shell { padding: 24px 20px 48px; max-width: 420px; margin: 120px auto; }

.hero-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 40px;
  line-height: 1.5;
  margin: 24px 0 10px;
}

.hero-sub { color: var(--ink-soft); font-size: 15px; margin: 0 0 28px; }

.auth-actions { display: flex; flex-direction: column; gap: 10px; align-items: stretch; }

.view-title { font-family: var(--font-display); font-weight: 700; font-size: 22px; margin: 8px 0 6px; }
.view-titlelogin { font-family: var(--font-display); font-weight: 800; font-size: 35px; margin: 8px 0 15px; }
.view-sub { color: var(--ink-soft); font-size: 14px; margin: 0 0 22px; }

.form { display: flex; flex-direction: column; gap: 16px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 13px; font-weight: 500; color: var(--ink-soft); }
.field-hint { font-size: 12px; color: #9AA69E; }
.field-error { color: var(--error); font-size: 12px; }

input, select {
  font-family: var(--font-body);
  font-size: 16px;
  padding: 12px 14px;
  border-radius: var(--radius-field);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--ink);
}

input.input-invalid { border-color: var(--error); }

.otp-input {
  width: 100%;
  font-family: var(--font-display);
  font-size: 28px;
  letter-spacing: 0.3em;
  text-align: center;
  padding: 16px;
  border-radius: var(--radius-field);
  border: 1px solid var(--border);
  margin-bottom: 4px;
}

.otp-timer { color: var(--ink-soft); font-size: 13px; margin: 8px 0 4px; }

.pin-field { display: flex; align-items: center; gap: 8px; }
.pin-field input { flex: 1; }
.pin-toggle {
  flex: none;
  background: none;
  border: none;
  color: var(--ink-soft);
  font-size: 12px;
  text-decoration: underline;
  padding: 4px;
}

.account-badge {
  font-size: 11px;
  color: #A8A8A8;
  letter-spacing: 0.02em;
}

/* Saved-notes list */
#view-list { padding: 20px 20px 40px; max-width: 720px; margin: 0 auto; }

.list-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 5px;
}

.list-header-text { display: flex; flex-direction: column; gap: 2px; }

.list-eyebrow { font-size: 30px; font-weight: 800; color: var(--ink-soft); margin-top: 40px;}

.list-greeting { font-family: var(--font-display); font-weight: 700; font-size: 24px; margin: 0; }

.list-header-actions { display: flex; align-items: center; gap: 6px; }

/* Search Bar */
.search-input {
  margin-top: 5px;
  margin-bottom: 22px;
  width: 100%;
  max-width: 480px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-field);
  font-family: var(--font-body);
  font-size: 14px;
  background: var(--bg);
  color: var(--ink);
  transition: border-color 0.2s ease;
}

mark.search-highlight {
  background-color: rgba(252, 163, 17, 0.4);
  color: inherit;
  padding: 0;
  border-radius: 2px;
}

.notes-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.note-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 16px;
  min-height: 190px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
  text-align: left;
  min-width: 0;
}

.note-card:hover { border-color: var(--primary); }

.note-card-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.note-card-preview {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 0;
  overflow: hidden;
}

.note-card-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-size: 12px;
  color: var(--ink-soft);
}

.note-card-row-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.note-card-row-qty { flex: none; color: var(--ink); font-weight: 500; }

.note-card-more { font-size: 11px; color: var(--ink-soft); }

.note-card-empty-preview { font-size: 12px; color: #B5B5B5; font-style: italic; }

.note-card-meta { display: flex; flex-direction: column; gap: 2px; }
.note-card-count { font-size: 12px; color: var(--ink-soft); }
.note-card-total { font-family: var(--font-display); font-weight: 600; font-size: 15px; color: var(--primary-dark); }
.note-card-edited { font-size: 11px; color: #A8A8A8; }
.note-card-edited.note-card-unsaved { color: var(--primary-dark); font-weight: 600; }

.empty-state {
  border: 1px dashed var(--border);
  border-radius: var(--radius-card);
  padding: 40px 24px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.empty-title { font-family: var(--font-display); font-weight: 600; font-size: 17px; margin: 0; }
.empty-sub { color: var(--ink-soft); font-size: 14px; margin: 0 0 6px; }

/* Floating Action Button */
.fab-btn {
  position: fixed;
  bottom: 60px;
  right: 15px;
  width: 75px;
  height: 75px;
  border-radius: 17px;
  background: var(--primary);
  color: #1A1200;
  border: none;
  font-size: 65px;
  font-weight: 150;
  box-shadow: 0 8px 24px rgba(252, 163, 17, 0.4);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  transition: transform 0.2s ease, background 0.2s ease;
}

.fab-btn:hover { 
  background: var(--primary-dark); 
  transform: scale(1.05); 
}


/* Skeleton loading (saved-notes cards, shown until real/cached data is ready) */
.note-card-skeleton { pointer-events: none; }

.skeleton-block {
  border-radius: 6px;
  background: linear-gradient(100deg, var(--secondary) 30%, #F2F2F2 50%, var(--secondary) 70%);
  background-size: 300% 100%;
  animation: skeleton-shimmer 1.3s ease-in-out infinite;
}

@keyframes skeleton-shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

.skeleton-title { height: 15px; width: 70%; margin-bottom: 10px; }
.skeleton-line { height: 10px; width: 100%; margin-bottom: 6px; }
.skeleton-line.short { width: 55%; }
.skeleton-total { height: 15px; width: 45%; margin-top: auto; }

/* Editor */
#view-editor { padding: 16px 16px 90px; max-width: 720px; margin: 0 auto; }

.editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 16px;
}

.editor-toolbar-group { display: flex; align-items: center; gap: 6px; }

.save-status {
  font-size: 13px;
  color: var(--success);
  margin: 0 0 8px;
}

.form-error {
  color: var(--error);
  background: var(--error-bg);
  border-radius: var(--radius-field);
  padding: 8px 12px;
  font-size: 13px;
  margin: 0 0 12px;
}

.title-input {
  display: block;
  width: 100%;
  text-align: center;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 22px;
  border: none;
  border-bottom: 2px solid var(--border);
  padding: 8px 4px 12px;
  margin: 0 0 18px;
  background: transparent;
  color: var(--ink);
}

.title-input:focus { outline: none; border-color: var(--primary); }

/* Materials table */
.table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  overflow: hidden;
}

.materials-table { width: 100%; border-collapse: collapse; background: var(--bg); table-layout: fixed; }

.materials-table th {
  background: var(--secondary);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 12px;
  text-align: left;
  padding: 10px 10px;
}

.materials-table td {
  border-top: 1px solid var(--border);
  padding: 6px 8px;
  vertical-align: middle;
}

.col-material { width: 35%; }
.col-qty { width: 14%; text-align: center; }
.col-price { width: 20%; }
.col-remove { width: 24px; }

.materials-table th.col-qty { text-align: center; }
.materials-table th.col-price { text-align: right; }

.cell-input {
  width: 100%;
  border: none;
  background: transparent;
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--ink);
  padding: 8px 4px;
  transition: font-size 0.1s ease;
}

.cell-input:focus { outline: none; background: #FFF7EA; border-radius: 6px; }

.material-input {
  display: block;
  resize: none;
  overflow: hidden;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: normal;
  line-height: 1.4;
  min-height: 34px;
}

.qty-input { text-align: center; }

.price-cell {
  display: flex;
  align-items: center;
  gap: 2px;
}

.currency-sign { color: var(--ink-soft); font-size: 13px; }

.price-input { text-align: right; }

.total-value {
  display: block;
  text-align: right;
  font-weight: 600;
  font-size: 14px;
  padding: 8px 4px;
  transition: font-size 0.1s ease;
}

.row-remove-btn {
  border: none;
  background: none;
  color: var(--ink-soft);
  font-size: 16px;
  line-height: 1;
  padding: 4px;
}

.row-remove-btn:hover { color: var(--error); }

/* Grand total row */
.grand-total-row td { background: var(--secondary); border-top: 2px solid var(--border); }
.grand-total-label {
  display: block;
  text-align: right;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
  padding: 8px 4px;
}
.grand-total-value { font-weight: 700; }

/* Suggestion bar */
.suggest-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg);
  border-top: 1px solid var(--border);
  padding: 10px 12px;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  z-index: 20;
}

.suggest-chip {
  flex: none;
  border: 1px solid var(--primary);
  background: #FFF7EA;
  color: var(--primary-dark);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}

.suggest-chip:hover { background: var(--primary); color: #1A1200; }

/* Small screens */
@media (max-width: 500px) {
  .notes-grid { grid-template-columns: 1fr; gap: 10px; }
  .note-card { padding: 14px; border-radius: 16px; }
  .fab-btn {
    bottom: 60px;
    right: 15px;
    width: 75px;
    height: 75px;
    font-size: 65px;
  }
  .title-input { font-size: 19px; }
}
