/* ============================================================
   MAGLIETTE COLLECTOR — theme.css
   Fedele al tema Flutter: Barlow, verde campo, oro trofeo
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Barlow:wght@400;500;600;700;800&display=swap');

/* --- CSS Variables (da AppColors) ---------------------------------------- */
:root {
  --primary:          #1A5C38;
  --primary-light:    #2E8B57;
  --primary-dark:     #0D3D24;
  --accent:           #D4A017;
  --accent-light:     #F0C040;

  --surface:          #0F1923;
  --surface-elevated: #1C2A35;
  --surface-card:     #243447;

  --text-primary:     #F4F4F4;
  --text-secondary:   #8FA3B1;
  --text-disabled:    #4A5E6A;

  --success:          #4CAF50;
  --error:            #E53935;
  --warning:          #FF8F00;

  --border-radius:    12px;
  --border-radius-lg: 16px;
  --nav-height:       64px;
  --header-height:    56px;
}

/* --- Reset & Base --------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: 'Barlow', sans-serif;
  background: var(--surface);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
button { font-family: 'Barlow', sans-serif; cursor: pointer; border: none; outline: none; }
input, select, textarea { font-family: 'Barlow', sans-serif; }

/* --- Layout principale ---------------------------------------------------- */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

#main-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding-bottom: calc(var(--nav-height) + 8px);
  -webkit-overflow-scrolling: touch;
}

/* --- Bottom Navigation ---------------------------------------------------- */
#bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--nav-height);
  background: var(--surface-elevated);
  border-top: 1px solid var(--surface-card);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 100;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 12px;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 600;
  flex: 1;
  background: none;
}

.nav-item .nav-icon {
  font-size: 22px;
  transition: all 0.2s ease;
}

.nav-item.active {
  color: var(--accent);
}

.nav-item.active .nav-indicator {
  background: rgba(26, 92, 56, 0.3);
  border-radius: 8px;
  padding: 4px 16px;
}

/* --- Header / AppBar ------------------------------------------------------ */
.page-header {
  position: sticky;
  top: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--surface-card);
  padding: 0 16px;
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 50;
}

.page-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: 0.2px;
}

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

/* --- Cards ---------------------------------------------------------------- */
.card {
  background: var(--surface-card);
  border-radius: var(--border-radius-lg);
  padding: 16px;
  margin: 6px 16px;
}

.card-elevated {
  background: var(--surface-elevated);
  border-radius: var(--border-radius-lg);
  padding: 16px;
}

/* --- Buttons -------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 24px;
  border-radius: var(--border-radius);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.5px;
  transition: all 0.2s ease;
  cursor: pointer;
  border: none;
}

.btn-primary {
  background: var(--primary);
  color: var(--text-primary);
}
.btn-primary:hover { background: var(--primary-light); }
.btn-primary:active { transform: scale(0.97); }

.btn-accent {
  background: var(--accent);
  color: #0F1923;
}
.btn-accent:hover { background: var(--accent-light); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  padding: 8px 12px;
}
.btn-ghost:hover { background: var(--surface-elevated); color: var(--text-primary); }

.btn-danger {
  background: transparent;
  color: var(--error);
  border: 1px solid var(--error);
}
.btn-danger:hover { background: rgba(229,57,53,0.1); }

.btn-sm {
  padding: 6px 14px;
  font-size: 12px;
}

.btn-icon {
  width: 40px; height: 40px;
  padding: 0;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface-elevated);
  color: var(--text-secondary);
  font-size: 18px;
  transition: all 0.2s;
}
.btn-icon:hover { background: var(--surface-card); color: var(--text-primary); }

.fab {
  position: fixed;
  bottom: calc(var(--nav-height) + 16px);
  right: 16px;
  width: 56px; height: 56px;
  border-radius: 16px;
  background: var(--primary);
  color: var(--text-primary);
  font-size: 24px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 16px rgba(26,92,56,0.4);
  z-index: 90;
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
}
.fab:hover { background: var(--primary-light); transform: scale(1.05); }
.fab:active { transform: scale(0.95); }

/* --- Form Inputs ---------------------------------------------------------- */
.form-group { margin-bottom: 16px; }

.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  letter-spacing: 0.3px;
}

.form-input, .form-select, .form-textarea {
  width: 100%;
  background: var(--surface-elevated);
  border: none;
  border-radius: var(--border-radius);
  padding: 12px 14px;
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 500;
  outline: none;
  transition: box-shadow 0.2s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  box-shadow: 0 0 0 2px var(--primary);
}
.form-input::placeholder { color: var(--text-disabled); }
.form-select option { background: var(--surface-elevated); }
.form-textarea { resize: vertical; min-height: 80px; }

.form-input:disabled, .form-select:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Switch toggle */
.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
}
.switch-label {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
}
.switch {
  position: relative;
  width: 44px; height: 24px;
  flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch-slider {
  position: absolute;
  inset: 0;
  background: var(--surface-card);
  border-radius: 12px;
  cursor: pointer;
  transition: 0.2s;
}
.switch-slider:before {
  content: '';
  position: absolute;
  width: 18px; height: 18px;
  left: 3px; top: 3px;
  background: var(--text-secondary);
  border-radius: 50%;
  transition: 0.2s;
}
.switch input:checked + .switch-slider { background: var(--primary); }
.switch input:checked + .switch-slider:before {
  transform: translateX(20px);
  background: white;
}

/* --- Badge stati ---------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.badge-venduta    { background: rgba(255,143,0,0.15);   color: var(--warning); }
.badge-arrivata   { background: rgba(76,175,80,0.15);   color: var(--success); }
.badge-ordinata,
.badge-in_arrivo  { background: rgba(46,139,87,0.15);   color: var(--primary-light); }
.badge-prenotata,
.badge-spedita    { background: rgba(212,160,23,0.15);  color: var(--accent); }
.badge-persa_acq,
.badge-persa_vend { background: rgba(229,57,53,0.15);   color: var(--error); }
.badge-default    { background: rgba(143,163,177,0.15); color: var(--text-secondary); }

/* --- List items ----------------------------------------------------------- */
.list-item {
  background: var(--surface-card);
  border-radius: var(--border-radius-lg);
  margin: 6px 16px;
  padding: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: background 0.15s;
  text-decoration: none;
  color: inherit;
}
.list-item:hover { background: #2a3d52; }
.list-item:active { transform: scale(0.99); }

.list-thumb {
  width: 56px; height: 56px;
  border-radius: 10px;
  object-fit: cover;
  background: var(--surface-elevated);
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-disabled);
  font-size: 22px;
  overflow: hidden;
}
.list-thumb img { width: 100%; height: 100%; object-fit: cover; }

.list-body { flex: 1; min-width: 0; }
.list-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.list-subtitle {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.list-meta { font-size: 12px; color: var(--text-secondary); }

/* --- Section headers ------------------------------------------------------ */
.section-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 20px 16px 10px;
}
.section-accent-bar {
  width: 3px; height: 16px;
  background: var(--accent);
  border-radius: 2px;
  flex-shrink: 0;
}
.section-title {
  font-size: 15px;
  font-weight: 800;
  color: var(--text-primary);
}

/* --- Info rows (dettaglio) ------------------------------------------------ */
.info-card {
  background: var(--surface-card);
  border-radius: var(--border-radius-lg);
  overflow: hidden;
  margin: 8px 16px;
}
.info-row {
  display: flex;
  align-items: flex-start;
  padding: 12px 16px;
  border-bottom: 1px solid var(--surface-elevated);
}
.info-row:last-child { border-bottom: none; }
.info-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  width: 130px;
  flex-shrink: 0;
  padding-top: 1px;
}
.info-value {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  flex: 1;
}
.info-value.empty { color: var(--text-disabled); font-style: italic; }

/* --- Loading shimmer ------------------------------------------------------ */
@keyframes shimmer {
  0%   { background-position: -400px 0; }
  100% { background-position: 400px 0; }
}
.shimmer {
  background: linear-gradient(90deg,
    var(--surface-elevated) 25%,
    var(--surface-card) 50%,
    var(--surface-elevated) 75%);
  background-size: 800px 100%;
  animation: shimmer 1.4s infinite linear;
  border-radius: var(--border-radius-lg);
}
.shimmer-item {
  height: 80px;
  margin: 6px 16px;
  border-radius: var(--border-radius-lg);
}

/* --- Empty & Error states ------------------------------------------------- */
.empty-state, .error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 32px;
  text-align: center;
  gap: 12px;
}
.empty-icon { font-size: 48px; color: var(--text-disabled); }
.empty-title { font-size: 16px; font-weight: 600; color: var(--text-secondary); }
.empty-sub   { font-size: 13px; color: var(--text-disabled); }

/* --- Modal / Dialog ------------------------------------------------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  opacity: 0;
  transition: opacity 0.25s;
}
.modal-overlay.open { opacity: 1; }

.modal {
  background: var(--surface-elevated);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 600px;
  max-height: 90dvh;
  display: flex;
  flex-direction: column;
  transform: translateY(40px);
  transition: transform 0.3s ease;
  overflow: hidden;
}
.modal-overlay.open .modal { transform: translateY(0); }

.modal-handle {
  width: 40px; height: 4px;
  background: var(--text-disabled);
  border-radius: 2px;
  margin: 12px auto 0;
  flex-shrink: 0;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--surface-card);
  flex-shrink: 0;
}
.modal-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
}
.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  -webkit-overflow-scrolling: touch;
}
.modal-footer {
  display: flex;
  gap: 10px;
  padding: 12px 20px;
  border-top: 1px solid var(--surface-card);
  flex-shrink: 0;
}
.modal-footer .btn { flex: 1; justify-content: center; }

/* --- Tabs ----------------------------------------------------------------- */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--surface-card);
  overflow-x: auto;
  scrollbar-width: none;
  padding: 0 16px;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: 12px 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
  background: none;
}
.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* --- Filters bar ---------------------------------------------------------- */
.filters-bar {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  overflow-x: auto;
  scrollbar-width: none;
  background: var(--surface);
}
.filters-bar::-webkit-scrollbar { display: none; }

.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  background: var(--surface-elevated);
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  border: 1px solid transparent;
  transition: all 0.2s;
  flex-shrink: 0;
}
.filter-chip.active {
  background: rgba(26,92,56,0.2);
  border-color: var(--primary-light);
  color: var(--primary-light);
}
.filter-chip .chip-remove {
  font-size: 14px;
  color: var(--text-disabled);
  line-height: 1;
}

/* --- Toast ---------------------------------------------------------------- */
#toast-container {
  position: fixed;
  bottom: calc(var(--nav-height) + 16px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}
.toast {
  background: var(--surface-card);
  color: var(--text-primary);
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  pointer-events: none;
  animation: toastIn 0.3s ease, toastOut 0.3s ease 2.7s forwards;
  border-left: 3px solid var(--primary);
  white-space: nowrap;
}
.toast.error { border-left-color: var(--error); }
.toast.success { border-left-color: var(--success); }

@keyframes toastIn  { from { opacity:0; transform: translateY(12px); } to { opacity:1; transform: translateY(0); } }
@keyframes toastOut { from { opacity:1; } to { opacity:0; } }

/* --- Image grid (galleria) ------------------------------------------------ */
.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 4px;
  padding: 8px 16px;
}
@media (min-width: 600px) {
  .media-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 6px; }
}
.media-cell {
  aspect-ratio: 1;
  background: var(--surface-elevated);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  position: relative;
}
.media-cell img, .media-cell video {
  width: 100%; height: 100%;
  object-fit: cover;
}
.media-cell .video-badge {
  position: absolute;
  top: 6px; right: 6px;
  background: rgba(0,0,0,0.6);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 10px;
  font-weight: 700;
  color: white;
}

/* --- Stat cards (dashboard) ----------------------------------------------- */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 16px;
}
.stat-card {
  border-radius: var(--border-radius-lg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
  overflow: hidden;
}
.stat-card-blue    { background: linear-gradient(135deg, #0A2A4A, #1565C0); }
.stat-card-green   { background: linear-gradient(135deg, var(--primary-dark), var(--primary)); }
.stat-card-gold    { background: linear-gradient(135deg, #7B5500, var(--accent)); }
.stat-card-surface { background: linear-gradient(135deg, var(--surface-elevated), var(--surface-card)); }

.stat-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: rgba(244,244,244,0.7);
}
.stat-value {
  font-size: 28px;
  font-weight: 800;
  color: white;
  line-height: 1.1;
}
.stat-sub {
  font-size: 11px;
  color: rgba(244,244,244,0.6);
}

/* --- Fullscreen viewer ---------------------------------------------------- */
#fullscreen-viewer {
  position: fixed;
  inset: 0;
  background: black;
  z-index: 500;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
#fullscreen-viewer.open { display: flex; }
#fullscreen-viewer img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  touch-action: pinch-zoom;
}
#fullscreen-viewer video {
  max-width: 100%;
  max-height: 100%;
}
.viewer-close {
  position: absolute;
  top: 16px; right: 16px;
  width: 40px; height: 40px;
  background: rgba(0,0,0,0.6);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  color: white;
  font-size: 20px;
  z-index: 10;
  border: none;
}

/* --- Responsive ----------------------------------------------------------- */
@media (min-width: 768px) {
  #bottom-nav {
    position: fixed;
    left: 0; top: 0; bottom: 0; right: auto;
    width: 220px;
    height: 100dvh;
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
    padding: 24px 12px;
    border-top: none;
    border-right: 1px solid var(--surface-card);
    gap: 4px;
  }
  .nav-brand {
    display: flex !important;
    align-items: center;
    gap: 10px;
    padding: 8px 12px 24px;
    font-size: 16px;
    font-weight: 800;
    color: var(--accent);
  }
  .nav-item {
    flex-direction: row;
    justify-content: flex-start;
    padding: 12px 16px;
    font-size: 13px;
    gap: 12px;
    flex: none;
  }
  .nav-item .nav-icon { font-size: 20px; }
  #main-content {
    margin-left: 220px;
    padding-bottom: 24px;
  }
  .fab { right: 24px; bottom: 24px; }
  #toast-container { bottom: 24px; }
}

@media (min-width: 1024px) {
  #main-content { max-width: 900px; }
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
  .media-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
}

/* --- Utilities ------------------------------------------------------------ */
.text-success { color: var(--success); }
.text-error   { color: var(--error); }
.text-warning { color: var(--warning); }
.text-accent  { color: var(--accent); }
.text-secondary { color: var(--text-secondary); }
.text-disabled  { color: var(--text-disabled); }
.fw-800 { font-weight: 800; }
.fw-700 { font-weight: 700; }
.fw-600 { font-weight: 600; }
.mt-8  { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-8  { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.px-16 { padding-left: 16px; padding-right: 16px; }
.py-16 { padding-top: 16px; padding-bottom: 16px; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8  { gap: 8px; }
.gap-12 { gap: 12px; }
.hidden { display: none !important; }
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--surface-card);
  border-top-color: var(--primary-light);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 40px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

.divider {
  height: 1px;
  background: var(--surface-card);
  margin: 8px 16px;
}

.nav-brand { display: none; }
