/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #1a2332;
  --primary-light: #243044;
  --accent: #c8a456;
  --accent-hover: #b8943e;
  --bg: #f4f6f9;
  --white: #ffffff;
  --text: #333333;
  --text-light: #6b7280;
  --border: #e2e8f0;
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --info: #3b82f6;
  --sidebar-w: 260px;
  --header-h: 64px;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-lg: 0 4px 12px rgba(0,0,0,.1);
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

img { max-width: 100%; height: auto; }

/* ===== LAYOUT ===== */
.dash-layout {
  display: flex;
  min-height: 100vh;
}

/* ===== SIDEBAR ===== */
.sidebar {
  width: var(--sidebar-w);
  background: var(--primary);
  color: #fff;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform .3s;
}

.sidebar-logo {
  padding: 24px 20px;
  border-bottom: 1px solid rgba(255,255,255,.1);
  text-align: center;
}

.sidebar-logo h2 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: .5px;
  color: var(--accent);
}

.sidebar-logo small {
  font-size: .75rem;
  color: rgba(255,255,255,.5);
  display: block;
  margin-top: 2px;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 0;
  list-style: none;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 24px;
  color: rgba(255,255,255,.7);
  font-size: .9rem;
  transition: all .2s;
  border-left: 3px solid transparent;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
  background: rgba(255,255,255,.08);
  color: #fff;
  border-left-color: var(--accent);
}

.sidebar-nav .nav-icon {
  width: 20px;
  text-align: center;
  font-size: 1.1rem;
}

.sidebar-footer {
  padding: 16px 24px;
  border-top: 1px solid rgba(255,255,255,.1);
}

.sidebar-footer .btn-logout {
  width: 100%;
  padding: 10px;
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.15);
  color: rgba(255,255,255,.7);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: .85rem;
  transition: all .2s;
}

.sidebar-footer .btn-logout:hover {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

/* ===== MAIN CONTENT ===== */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
}

/* ===== HEADER ===== */
.dash-header {
  height: var(--header-h);
  background: var(--white);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.dash-header h1 {
  font-size: 1.25rem;
  font-weight: 600;
}

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

.hamburger {
  display: none;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text);
}

/* ===== PAGE BODY ===== */
.dash-body {
  padding: 32px;
  flex: 1;
}

/* ===== CARDS ===== */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}

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

.card-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
}

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius);
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all .2s;
  text-decoration: none;
  line-height: 1.4;
}

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

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

.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; color: #fff; }

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #16a34a; color: #fff; }

.btn-sm { padding: 5px 10px; font-size: .8rem; }

.btn-icon {
  width: 32px; height: 32px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--white);
  cursor: pointer;
  color: var(--text-light);
  transition: all .2s;
}

.btn-icon:hover { border-color: var(--accent); color: var(--accent); }
.btn-icon.danger:hover { border-color: var(--danger); color: var(--danger); }

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

.toolbar-left, .toolbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.search-box {
  position: relative;
}

.search-box input {
  padding: 8px 12px 8px 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .875rem;
  width: 280px;
  outline: none;
  transition: border-color .2s;
}

.search-box input:focus { border-color: var(--accent); }

.search-box::before {
  content: "\1F50D";
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: .85rem;
}

.filter-select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .875rem;
  background: var(--white);
  outline: none;
  cursor: pointer;
}

.filter-select:focus { border-color: var(--accent); }

/* ===== TABLE ===== */
.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  text-align: left;
  padding: 12px 16px;
  font-size: .8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-light);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 12px 16px;
  font-size: .875rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tbody tr:hover { background: #f8fafc; }

.table-thumb {
  width: 60px;
  height: 42px;
  object-fit: cover;
  border-radius: 4px;
}

.table-actions {
  display: flex;
  gap: 6px;
}

/* ===== BADGES ===== */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: .75rem;
  font-weight: 600;
  line-height: 1.4;
}

.badge-success { background: #dcfce7; color: #166534; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-info { background: #dbeafe; color: #1e40af; }
.badge-neutral { background: #f1f5f9; color: #475569; }

/* ===== FORMS ===== */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group.full-width {
  grid-column: 1 / -1;
}

.form-group label {
  font-size: .85rem;
  font-weight: 600;
  color: var(--text);
}

.form-group label .required {
  color: var(--danger);
}

.form-group input,
.form-group select,
.form-group textarea {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .9rem;
  font-family: inherit;
  outline: none;
  transition: border-color .2s;
  background: var(--white);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(200,164,86,.12);
}

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

.form-group input[type="checkbox"] {
  width: auto;
  margin-right: 8px;
}

.form-check {
  display: flex;
  align-items: center;
  gap: 8px;
}

.form-check label {
  font-weight: 400;
  cursor: pointer;
}

.form-hint {
  font-size: .78rem;
  color: var(--text-light);
}

.form-actions {
  display: flex;
  gap: 12px;
  margin-top: 24px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

/* ===== PHOTO UPLOAD ===== */
.photo-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 8px;
}

.photo-item {
  position: relative;
  width: 120px;
  height: 90px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}

.photo-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-item .photo-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  background: var(--danger);
  color: #fff;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  font-size: .7rem;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity .2s;
}

.photo-item:hover .photo-remove { opacity: 1; }

.photo-add {
  width: 120px;
  height: 90px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-light);
  font-size: .78rem;
  transition: all .2s;
  gap: 4px;
}

.photo-add:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.photo-add span { font-size: 1.5rem; }

/* ===== RICH TEXT EDITOR ===== */
.editor-toolbar {
  display: flex;
  gap: 4px;
  padding: 8px;
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
  background: #f8fafc;
  flex-wrap: wrap;
}

.editor-toolbar button {
  padding: 6px 10px;
  background: none;
  border: 1px solid transparent;
  border-radius: 4px;
  cursor: pointer;
  font-size: .85rem;
  color: var(--text);
  transition: all .15s;
}

.editor-toolbar button:hover { background: var(--border); }
.editor-toolbar button.active { background: var(--accent); color: #fff; }

.editor-area {
  border: 1px solid var(--border);
  border-radius: 0 0 var(--radius) var(--radius);
  min-height: 200px;
  padding: 16px;
  outline: none;
  font-family: inherit;
  font-size: .9rem;
  line-height: 1.7;
}

.editor-area:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(200,164,86,.12);
}

.editor-area h2 { font-size: 1.2rem; margin: 12px 0 8px; }
.editor-area h3 { font-size: 1.05rem; margin: 10px 0 6px; }
.editor-area p { margin-bottom: 8px; }
.editor-area a { color: var(--accent); text-decoration: underline; }
.editor-area ul, .editor-area ol { margin-left: 24px; margin-bottom: 8px; }

/* ===== LOGIN ===== */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--primary);
}

.login-card {
  background: var(--white);
  border-radius: 12px;
  padding: 48px 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.login-card h1 {
  font-size: 1.5rem;
  margin-bottom: 4px;
  color: var(--primary);
}

.login-card .login-subtitle {
  color: var(--text-light);
  font-size: .9rem;
  margin-bottom: 32px;
}

.login-card .form-group {
  text-align: left;
  margin-bottom: 16px;
}

.login-card .btn { width: 100%; justify-content: center; padding: 12px; }

.login-error {
  display: none;
  background: #fee2e2;
  color: #991b1b;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: .85rem;
  margin-bottom: 16px;
}

.login-error.show { display: block; }

/* ===== STATS ROW ===== */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.stat-card .stat-label {
  font-size: .8rem;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: .5px;
  font-weight: 600;
}

.stat-card .stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--primary);
  margin-top: 4px;
}

/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-light);
}

.empty-state span { font-size: 3rem; display: block; margin-bottom: 12px; }

/* ===== TOAST / ALERTS ===== */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 14px 24px;
  border-radius: var(--radius);
  color: #fff;
  font-size: .9rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 9999;
  transform: translateY(100px);
  opacity: 0;
  transition: all .3s;
}

.toast.show { transform: translateY(0); opacity: 1; }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.info { background: var(--info); }

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.modal-overlay.show { display: flex; }

.modal {
  background: var(--white);
  border-radius: 12px;
  padding: 32px;
  max-width: 440px;
  width: 90%;
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.modal h3 { margin-bottom: 12px; }
.modal p { color: var(--text-light); margin-bottom: 24px; font-size: .9rem; }

.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

/* ===== TOGGLE SWITCH ===== */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: #cbd5e1;
  border-radius: 24px;
  transition: background .2s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  background: white;
  border-radius: 50%;
  transition: transform .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}

.toggle-switch input:checked + .toggle-slider {
  background: var(--accent);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(20px);
}

.toggle-switch.sm {
  width: 36px;
  height: 20px;
}

.toggle-switch.sm .toggle-slider::before {
  width: 14px;
  height: 14px;
}

.toggle-switch.sm input:checked + .toggle-slider::before {
  transform: translateX(16px);
}

.toggle-label-text {
  font-size: .85rem;
  color: var(--text-light);
}

/* ===== CHIP INPUT ===== */
.chip-input-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 44px;
  align-items: center;
  background: var(--white);
  cursor: text;
  transition: border-color .2s;
}

.chip-input-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(200,164,86,.12);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--primary-light);
  color: #fff;
  padding: 3px 8px;
  border-radius: 20px;
  font-size: .78rem;
  font-weight: 500;
  white-space: nowrap;
}

.chip button {
  background: none;
  border: none;
  color: rgba(255,255,255,.7);
  cursor: pointer;
  font-size: .9rem;
  line-height: 1;
  padding: 0;
  display: flex;
  align-items: center;
}

.chip button:hover { color: #fff; }

.chip-input {
  border: none;
  outline: none;
  font-size: .875rem;
  font-family: inherit;
  min-width: 140px;
  flex: 1;
  padding: 0;
  background: transparent;
}

/* ===== FORM SECTIONS ===== */
.form-section {
  border: 1px solid var(--border);
}

.form-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  padding: 16px 24px;
  margin: -24px -24px 0;
  border-radius: var(--radius) var(--radius) 0 0;
  user-select: none;
  transition: background .15s;
}

.form-section-header:hover {
  background: #f8fafc;
}

.form-section-header h2 {
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
}

.section-toggle {
  color: var(--text-light);
  font-size: .8rem;
}

.form-section-body {
  padding-top: 20px;
}

/* ===== BADGE STATO PUBBLICAZIONE ===== */
.badge-available { background: #dcfce7; color: #166534; }
.badge-sold      { background: #f1f5f9; color: #475569; }
.badge-rented    { background: #dbeafe; color: #1e40af; }
.badge-withdrawn { background: #fee2e2; color: #991b1b; }

/* ===== RESPONSIVE ===== */
@media (max-width: 1024px) {
  .form-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .hamburger { display: block; }
  .dash-body { padding: 20px 16px; }
  .dash-header { padding: 0 16px; }
  .search-box input { width: 180px; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar-left, .toolbar-right { justify-content: space-between; }
  .stats-row { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 480px) {
  .stats-row { grid-template-columns: 1fr; }
  .login-card { padding: 32px 24px; margin: 16px; }
}
