@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;1,9..40,400&display=swap');

:root {
  --bg:           #F5EFE6;
  --surface:      #FFFFFF;
  --surface-2:    #EDE7DC;
  --border:       #D9D0C4;
  --text:         #1E1E1E;
  --text-muted:   #7D7168;
  --accent:       #1E1E1E;
  --accent-hover: #3D3D3D;
  --ok-bg:        #EAF3EC;
  --ok-text:      #3D7A52;
  --ok-border:    #BDD8C6;
  --danger:       #B83232;
  --danger-light: #FDF0EF;
  --danger-border:#F0C4C0;
  --radius:       10px;
  --radius-sm:    6px;
  --shadow:       0 1px 4px rgba(0,0,0,0.08);
  --shadow-md:    0 6px 24px rgba(0,0,0,0.12);
  --transition:   0.15s ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* ──────────────────────────────────────────────────────────
   AUTH
────────────────────────────────────────────────────────── */
#auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 40px;
  width: 100%;
  max-width: 400px;
}

.auth-card h1 {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-bottom: 4px;
}

.auth-subtitle {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 28px;
}

.auth-toggle {
  text-align: center;
  margin-top: 20px;
  font-size: 14px;
  color: var(--text-muted);
}

.auth-toggle a {
  color: var(--text);
  font-weight: 500;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ──────────────────────────────────────────────────────────
   FORMS
────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }

.form-group label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.form-group input,
.form-group textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 15px;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color var(--transition);
}

.form-group input:focus,
.form-group textarea:focus { border-color: var(--accent); }

.form-group textarea { resize: vertical; min-height: 80px; }

.error-msg {
  background: var(--danger-light);
  color: var(--danger);
  border: 1px solid var(--danger-border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 16px;
  display: none;
}
.error-msg.show { display: block; }

/* ──────────────────────────────────────────────────────────
   BUTTONS
────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), opacity var(--transition);
  white-space: nowrap;
  text-decoration: none;
  line-height: 1;
}

.btn-primary   { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary { background: var(--surface-2); color: var(--text); }
.btn-secondary:hover { background: var(--border); }

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1.5px solid var(--danger-border);
}
.btn-danger:hover { background: var(--danger-light); }

.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-full { width: 100%; justify-content: center; }

.btn-icon {
  width: 34px; height: 34px;
  border: none;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: background var(--transition), color var(--transition);
  flex-shrink: 0;
}
.btn-icon:hover { background: var(--surface-2); color: var(--text); }

/* ──────────────────────────────────────────────────────────
   APP HEADER
────────────────────────────────────────────────────────── */
#app-screen  { display: none; }
#app-header  { display: none; }

.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 28px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
}


.logo {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.logo span { color: var(--text-muted); font-weight: 400; }

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

.user-menu {
  position: relative;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px 5px 6px;
  background: var(--surface-2);
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
}

.user-dropdown {
  display: none;
  position: fixed;
  top: 60px;
  right: 20px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  min-width: 190px;
  padding: 6px;
  z-index: 9999;
}

.user-dropdown.open {
  display: block;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 9px 12px;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 14px;
  font-weight: 400;
  cursor: pointer;
  color: var(--text);
  text-align: left;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
}
.dropdown-item:hover { background: var(--surface-2); }
.dropdown-item.danger { color: var(--danger); }
.dropdown-item.danger:hover { background: var(--danger-light); }

.dropdown-theme-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
  user-select: none;
}
.dropdown-theme-row:hover { background: var(--surface-2); }

.toggle-sw {
  position: relative;
  width: 34px;
  height: 18px;
  flex-shrink: 0;
}
.toggle-sw input { display: none; }
.toggle-knob {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 9px;
  transition: background 0.18s;
}
.toggle-knob::before {
  content: '';
  position: absolute;
  width: 12px;
  height: 12px;
  top: 3px;
  left: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.18s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.25);
}
.toggle-sw input:checked + .toggle-knob { background: var(--accent); }
.toggle-sw input:checked + .toggle-knob::before { transform: translateX(16px); }

.avatar {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* ──────────────────────────────────────────────────────────
   MAIN
────────────────────────────────────────────────────────── */
.app-main {
  max-width: 720px;
  margin: 0 auto;
  padding: calc(64px + 24px) 28px 60px;
}

/* ──────────────────────────────────────────────────────────
   TOOLBAR
────────────────────────────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
  flex-wrap: wrap;
}

.price-total {
  display: none;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  margin-bottom: 20px;
}
.price-total strong { color: var(--text); font-weight: 600; }
.price-total-note   { font-size: 12px; }

.filter-tabs {
  display: flex;
  gap: 3px;
  background: var(--surface-2);
  padding: 4px;
  border-radius: var(--radius-sm);
}

.filter-tab {
  padding: 6px 14px;
  border: none;
  background: transparent;
  border-radius: 4px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-muted);
  transition: background var(--transition), color var(--transition);
}
.filter-tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

/* ──────────────────────────────────────────────────────────
   ITEM LIST
────────────────────────────────────────────────────────── */
.items-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.item-card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1.5px solid var(--border);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition);
  user-select: none;
}
.item-card:hover { border-color: #B5ADA4; box-shadow: var(--shadow); }

.item-card.purchased {
  background: var(--ok-bg);
  border-color: var(--ok-border);
}
.item-card.purchased .item-name {
  text-decoration: line-through;
  color: var(--text-muted);
}

/* Custom checkbox */
.item-checkbox {
  flex-shrink: 0;
  width: 22px; height: 22px;
  border-radius: 6px;
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), border-color var(--transition);
}
.item-checkbox.checked {
  background: var(--ok-text);
  border-color: var(--ok-text);
}
.item-checkbox.checked::after {
  content: '';
  width: 5px; height: 9px;
  border: 2px solid #fff;
  border-top: none;
  border-left: none;
  transform: rotate(42deg) translateY(-1px);
}

.item-info { flex: 1; min-width: 0; }

.item-name {
  font-size: 15px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 5px;
  flex-wrap: wrap;
}

.chip {
  font-size: 11px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 20px;
  background: var(--surface-2);
  color: var(--text-muted);
  white-space: nowrap;
}
.chip.price { background: #EEE8DE; color: #6A5540; }
.chip.link  { background: #E4E8F0; color: #3A4A6A; }

.item-arrow {
  flex-shrink: 0;
  color: var(--border);
  font-size: 20px;
  line-height: 1;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 64px 24px;
  color: var(--text-muted);
}
.empty-state .es-icon { font-size: 40px; margin-bottom: 14px; }
.empty-state p { font-size: 15px; line-height: 1.6; }

/* Loader */
.loader { display: flex; justify-content: center; padding: 48px; }
.spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--text-muted);
  border-radius: 50%;
  animation: spin .75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ──────────────────────────────────────────────────────────
   MODAL
────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(30, 20, 10, 0.35);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  padding: 16px;
}
@media (min-width: 600px) {
  .modal-overlay { align-items: center; }
}
.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  transform: translateY(16px);
  transition: transform 0.2s ease;
  box-shadow: var(--shadow-md);
}
.modal-overlay.open .modal { transform: translateY(0); }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 24px 0;
}
.modal-header h2 {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.modal-body { padding: 20px 24px; }

.modal-footer {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding: 0 24px 24px;
  flex-wrap: wrap;
}

/* ──────────────────────────────────────────────────────────
   DETAIL VIEW
────────────────────────────────────────────────────────── */
.detail-section { margin-bottom: 20px; }
.detail-section:last-child { margin-bottom: 0; }

.detail-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.detail-value { font-size: 15px; color: var(--text); }

.detail-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}

/* ──────────────────────────────────────────────────────────
   LINKS
────────────────────────────────────────────────────────── */
.links-editor { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }

.link-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.link-row .link-url   { flex: 1; }
.link-row .link-label { flex: 0 0 150px; }

.view-links { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }

.view-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--accent);
  text-decoration: none;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  transition: background var(--transition);
  overflow: hidden;
}
.view-link span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.view-link:hover { background: var(--surface-2); }

/* ──────────────────────────────────────────────────────────
   USERS MODAL
────────────────────────────────────────────────────────── */
.user-row {
  display: flex;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.user-row:last-child { border-bottom: none; }
.user-row .user-info { flex: 1; min-width: 0; }
.user-name { font-weight: 500; font-size: 14px; }
.user-email { font-size: 12px; color: var(--text-muted); margin-top: 1px; }

.role-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 20px;
  background: var(--surface-2);
  color: var(--text-muted);
  margin-left: 6px;
}
.role-badge.admin { background: #EDE8F5; color: #6B4FA0; }

/* ──────────────────────────────────────────────────────────
   TOAST
────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--accent);
  color: #fff;
  padding: 10px 22px;
  border-radius: 24px;
  font-size: 14px;
  font-weight: 500;
  z-index: 999;
  transition: transform 0.25s ease;
  pointer-events: none;
  white-space: nowrap;
  box-shadow: var(--shadow-md);
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* ──────────────────────────────────────────────────────────
   DARK THEME
────────────────────────────────────────────────────────── */
html[data-theme="dark"] {
  --bg:           #1C1917;
  --surface:      #252220;
  --surface-2:    #2E2B27;
  --border:       #3D3933;
  --text:         #EDE7DC;
  --text-muted:   #7D7168;
  --accent:       #EDE7DC;
  --accent-hover: #C8C0B4;
  --ok-bg:        #1A2E21;
  --ok-text:      #5A9E6A;
  --ok-border:    #2A4A32;
  --danger:       #E06060;
  --danger-light: #2A1818;
  --danger-border:#4A2828;
  --shadow:       0 1px 4px rgba(0,0,0,0.3);
  --shadow-md:    0 6px 24px rgba(0,0,0,0.5);
}

html[data-theme="dark"] .btn-primary       { color: var(--bg); }
html[data-theme="dark"] .avatar            { color: var(--bg); }
html[data-theme="dark"] .toast             { color: var(--bg); }

html[data-theme="dark"] .chip.price        { background: #2E2820; color: #C4A882; }
html[data-theme="dark"] .chip.link         { background: #1E2432; color: #8A9EC8; }

html[data-theme="dark"] .role-badge.owner,
html[data-theme="dark"] .role-badge.admin  { background: #2E2840; color: #B09ACC; }

html[data-theme="dark"] .view-link         { color: var(--text); }

html[data-theme="dark"] .filter-tab.active { box-shadow: 0 1px 3px rgba(0,0,0,0.4); }

/* ──────────────────────────────────────────────────────────
   RESPONSIVE
────────────────────────────────────────────────────────── */
@media (max-width: 520px) {
  .app-header   { padding: 0 16px; }
  .app-main     { padding: calc(64px + 16px) 16px 48px; }
  .auth-card    { padding: 28px 20px; }
  .toolbar      { flex-direction: column; align-items: stretch; }
  .toolbar .btn { width: 100%; justify-content: center; }
  .link-row     { flex-wrap: wrap; }
  .link-row .link-label { flex: 0 0 100%; }
  .modal-header h2 { font-size: 16px; }
  #user-name { display: none; }
  .btn-icon { width: 44px; height: 44px; font-size: 18px; }
}

@media (min-width: 521px) and (max-width: 1024px) {
  .btn-icon { width: 40px; height: 40px; font-size: 17px; }
}
