/* ARTIDEV app styles — mobile-first, professional blue/gray theme */
:root {
  --bg: #F0F2F5;
  --card: #FFFFFF;
  --blue: #1E3A5F;
  --blue-light: #E8EDF3;
  --blue-mid: #2C5282;
  --accent: #F2590C;
  --accent-light: #FEF0E6;
  --text: #1A202C;
  --text-muted: #64748B;
  --text-light: #94A3B8;
  --border: #E2E8F0;
  --green: #16A34A;
  --green-light: #DCFCE7;
  --red: #DC2626;
  --red-light: #FEE2E2;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  font-family: var(--font);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

/* --- Nav --- */
.app-nav {
  background: var(--blue);
  color: #fff;
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.nav-brand {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}
.nav-tabs {
  display: flex;
  gap: 0.25rem;
}
.nav-tab {
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.7);
  font-family: var(--font);
  font-size: 0.8rem;
  font-weight: 500;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.nav-tab:hover { background: rgba(255,255,255,0.1); color: #fff; }
.nav-tab.active {
  background: rgba(255,255,255,0.2);
  color: #fff;
  font-weight: 600;
}

/* --- Content --- */
.app-content {
  max-width: 720px;
  margin: 0 auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding-bottom: 3rem;
}

/* --- Cards --- */
.section-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.section-title-sm {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--blue);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 1rem;
}

/* --- Forms --- */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}
.form-group { display: flex; flex-direction: column; gap: 0.3rem; }
.form-group.full-width { grid-column: 1 / -1; }
.form-group label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.form-group input,
.form-group select {
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  font-family: var(--font);
  font-size: 0.9rem;
  color: var(--text);
  background: var(--bg);
  transition: border-color 0.15s;
  width: 100%;
}
.form-group input:focus {
  outline: none;
  border-color: var(--blue-mid);
  background: #fff;
}

/* --- Trade grid --- */
.trade-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 0.5rem;
}
.trade-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  padding: 0.75rem 0.5rem;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  transition: all 0.15s;
}
.trade-btn:hover { border-color: var(--blue-mid); color: var(--blue); }
.trade-btn.active {
  border-color: var(--blue);
  background: var(--blue-light);
  color: var(--blue);
  font-weight: 600;
}

/* --- Items list --- */
.items-list { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 1rem; }
.item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0.75rem;
  background: var(--bg);
  border-radius: 8px;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.item-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  min-width: 150px;
}
.item-tag {
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  white-space: nowrap;
}
.tag-mat { background: var(--blue-light); color: var(--blue); }
.tag-labor { background: var(--green-light); color: var(--green); }
.tag-expense { background: var(--accent-light); color: var(--accent); }
.item-name {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 200px;
}
.item-controls {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
}
.item-qty, .item-price {
  width: 60px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.3rem 0.4rem;
  font-family: var(--font);
  font-size: 0.82rem;
  text-align: right;
  background: #fff;
  color: var(--text);
}
.item-qty:focus, .item-price:focus { outline: none; border-color: var(--blue-mid); }
.item-unit, .item-euro, .item-multiply {
  font-size: 0.75rem;
  color: var(--text-light);
}
.item-total {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--blue);
  min-width: 70px;
  text-align: right;
}
.btn-remove {
  background: none;
  border: none;
  color: var(--red);
  font-size: 1rem;
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  line-height: 1;
}
.btn-remove:hover { background: var(--red-light); }

/* --- Add actions --- */
.add-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.btn-add {
  padding: 0.5rem 1rem;
  border: 1.5px dashed var(--border);
  border-radius: 8px;
  background: #fff;
  font-family: var(--font);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--blue);
  cursor: pointer;
  transition: all 0.15s;
}
.btn-add:hover { border-color: var(--blue); background: var(--blue-light); }
.btn-add-labor { color: var(--green); }
.btn-add-labor:hover { border-color: var(--green); background: var(--green-light); }
.btn-add-expense { color: var(--accent); }
.btn-add-expense:hover { border-color: var(--accent); background: var(--accent-light); }

/* --- AI Estimate bar --- */
.ai-estimate-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: linear-gradient(135deg, var(--blue) 0%, #1a4a7a 100%);
  border-radius: 10px;
  margin-bottom: 0.75rem;
}
.btn-ai {
  padding: 0.6rem 1.25rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-family: var(--font);
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn-ai:hover { background: #d94e0a; transform: translateY(-1px); }
.ai-hint {
  font-size: 0.78rem;
  color: rgba(255,255,255,0.7);
  line-height: 1.4;
}

/* --- Estimate Modal --- */
.estimate-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.estimate-modal-content {
  background: var(--card);
  border-radius: 16px;
  width: 100%;
  max-width: 480px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  overflow: hidden;
}
.modal-header {
  background: var(--blue);
  color: #fff;
  padding: 1.25rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-title { font-size: 1.1rem; font-weight: 700; }
.modal-close {
  background: none;
  border: none;
  color: rgba(255,255,255,0.7);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
}
.modal-close:hover { background: rgba(255,255,255,0.15); color: #fff; }
.modal-body { padding: 1.5rem; }
.modal-trade { font-size: 0.85rem; color: var(--text-muted); }
.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
}
.modal-footer .btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }
.ai-loading {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem;
  background: var(--blue-light);
  border-radius: 8px;
  margin-top: 0.75rem;
  font-size: 0.88rem;
  color: var(--blue);
}
.ai-spinner {
  width: 20px;
  height: 20px;
  border: 2.5px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }
.ai-error {
  padding: 0.75rem 1rem;
  background: var(--red-light);
  border: 1px solid var(--red);
  border-radius: 8px;
  color: var(--red);
  font-size: 0.85rem;
  margin-top: 0.75rem;
}

/* --- Material picker --- */
.material-picker { border: 2px solid var(--blue-light); }
.search-input {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  font-family: var(--font);
  font-size: 0.9rem;
  margin-bottom: 0.75rem;
  background: var(--bg);
}
.search-input:focus { outline: none; border-color: var(--blue-mid); background: #fff; }
.material-list {
  max-height: 300px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.material-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 0.75rem;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.1s;
}
.material-item:hover { background: var(--blue-light); }
.mat-name { font-size: 0.85rem; color: var(--text); }
.mat-price { font-size: 0.8rem; font-weight: 600; color: var(--blue); white-space: nowrap; }

/* --- Totals --- */
.totals-card { border: 2px solid var(--blue-light); }
.totals-grid { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 1.25rem; }
.total-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.88rem;
  padding: 0.25rem 0;
}
.total-row.muted { color: var(--text-muted); font-size: 0.82rem; }
.total-row.bold {
  font-weight: 700;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}
.total-row.grand-total {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--blue);
  padding: 0.75rem;
  background: var(--blue-light);
  border-radius: 8px;
  margin-top: 0.25rem;
}

/* --- Action buttons --- */
.action-buttons {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.btn-primary {
  padding: 0.7rem 1.25rem;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  flex: 1;
  min-width: 140px;
}
.btn-primary:hover { background: var(--blue-mid); }
.btn-secondary {
  padding: 0.7rem 1.25rem;
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-secondary:hover { opacity: 0.9; }
.btn-outline {
  padding: 0.7rem 1.25rem;
  background: #fff;
  color: var(--text-muted);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-outline:hover { border-color: var(--blue); color: var(--blue); }
.btn-sm { padding: 0.4rem 0.75rem; font-size: 0.78rem; }

/* --- Logo upload --- */
.logo-upload {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.logo-preview {
  width: 80px;
  height: 80px;
  object-fit: contain;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

/* --- History --- */
.history-list { display: flex; flex-direction: column; gap: 0.5rem; }
.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.85rem 1rem;
  background: var(--bg);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.history-item:hover { background: var(--blue-light); }
.hist-main { display: flex; flex-direction: column; gap: 0.15rem; }
.hist-client { font-size: 0.9rem; font-weight: 600; color: var(--text); }
.hist-desc { font-size: 0.78rem; color: var(--text-muted); }
.hist-meta { display: flex; align-items: center; gap: 0.75rem; }
.hist-trade { font-size: 0.78rem; color: var(--text-muted); }
.hist-total { font-size: 0.95rem; font-weight: 700; color: var(--blue); }
.hist-date { font-size: 0.72rem; color: var(--text-light); }

/* --- Misc --- */
.empty-state {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-light);
  font-size: 0.88rem;
}
.save-msg {
  margin-top: 0.75rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--green);
}

/* --- Responsive --- */
@media (max-width: 640px) {
  .app-nav { flex-direction: column; gap: 0.5rem; }
  .nav-tabs { width: 100%; justify-content: center; }
  .nav-tab { font-size: 0.72rem; padding: 0.4rem 0.5rem; }
  .form-grid { grid-template-columns: 1fr; }
  .trade-grid { grid-template-columns: repeat(3, 1fr); }
  .item-row { flex-direction: column; align-items: flex-start; }
  .item-controls { width: 100%; justify-content: flex-end; }
  .item-name { max-width: 100%; }
  .action-buttons { flex-direction: column; }
  .btn-secondary, .btn-outline { width: 100%; text-align: center; }
}
