/* === Design Tokens === */
:root {
  --md-primary: #1976D2;
  --md-primary-dark: #1565C0;
  --md-on-primary: #ffffff;
  --md-surface: #ffffff;
  --md-surface-variant: #f5f5f5;
  --md-background: #fafafa;
  --md-on-surface: #212121;
  --md-on-surface-variant: #616161;
  --md-error: #D32F2F;
  --md-success: #388E3C;
  --md-outline: #e0e0e0;
  --md-elevation-1: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.08);
  --md-elevation-2: 0 3px 6px rgba(0,0,0,0.12), 0 2px 4px rgba(0,0,0,0.08);
  --md-elevation-3: 0 6px 12px rgba(0,0,0,0.12), 0 4px 8px rgba(0,0,0,0.06);
  --md-radius-sm: 8px;
  --md-radius-md: 12px;
  --md-radius-lg: 16px;
  --md-spacing-xs: 4px;
  --md-spacing-sm: 8px;
  --md-spacing-md: 16px;
  --md-spacing-lg: 24px;
  --md-spacing-xl: 32px;
  --md-app-bar-height: 56px;
  --md-bottom-nav-height: 56px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
  font-family: 'Roboto', sans-serif;
  background: var(--md-background);
  color: var(--md-on-surface);
  -webkit-font-smoothing: antialiased;
}

/* === App Bar === */
.app-bar {
  position: sticky;
  top: 0;
  z-index: 1100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--md-app-bar-height);
  padding: 0 var(--md-spacing-sm);
  background: var(--md-primary);
  color: var(--md-on-primary);
  box-shadow: var(--md-elevation-2);
}

.app-bar.hidden {
  display: none;
}

.app-bar-left {
  display: flex;
  align-items: center;
  gap: var(--md-spacing-sm);
}

.app-bar-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--md-on-primary);
  cursor: pointer;
  transition: background 0.2s;
}

.app-bar-icon-btn:hover {
  background: rgba(255,255,255,0.12);
}

.app-bar-icon-btn.hidden {
  display: none;
}

.app-bar-title {
  font-size: 1.125rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-bar-right {
  position: relative;
  display: flex;
  align-items: center;
}

.app-bar-user-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  border: none;
  background: transparent;
  color: var(--md-on-primary);
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 20px;
  transition: background 0.2s;
  font-family: inherit;
  font-size: 0.875rem;
}

.app-bar-user-btn:hover {
  background: rgba(255,255,255,0.12);
}

.app-bar-username {
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* === User Menu Dropdown === */
.app-bar-user-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 200px;
  background: var(--md-surface);
  border-radius: var(--md-radius-sm);
  box-shadow: var(--md-elevation-3);
  overflow: hidden;
  z-index: 1200;
}

.app-bar-user-menu.hidden {
  display: none;
}

.user-menu-header {
  display: flex;
  align-items: center;
  gap: var(--md-spacing-sm);
  padding: var(--md-spacing-md);
  color: var(--md-on-surface);
  font-weight: 500;
  font-size: 0.875rem;
}

.user-menu-header .material-icons {
  color: var(--md-on-surface-variant);
}

.user-menu-divider {
  height: 1px;
  background: var(--md-outline);
}

.user-menu-item {
  display: flex;
  align-items: center;
  gap: var(--md-spacing-sm);
  width: 100%;
  padding: 12px var(--md-spacing-md);
  border: none;
  background: transparent;
  color: var(--md-on-surface);
  font-family: inherit;
  font-size: 0.875rem;
  cursor: pointer;
  transition: background 0.15s;
}

.user-menu-item:hover {
  background: var(--md-surface-variant);
}

.user-menu-item .material-icons {
  font-size: 20px;
  color: var(--md-on-surface-variant);
}

/* === Bottom Navigation === */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1100;
  display: flex;
  align-items: center;
  justify-content: space-around;
  height: var(--md-bottom-nav-height);
  background: var(--md-surface);
  box-shadow: 0 -1px 4px rgba(0,0,0,0.1);
}

.bottom-nav.hidden {
  display: none;
}

.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  gap: 2px;
  border: none;
  background: transparent;
  color: var(--md-on-surface-variant);
  cursor: pointer;
  padding: 6px 0;
  transition: color 0.2s;
  font-family: inherit;
  min-width: 0;
}

.bottom-nav-item .material-icons {
  font-size: 24px;
  transition: color 0.2s;
}

.bottom-nav-label {
  font-size: 0.7rem;
  font-weight: 500;
  white-space: nowrap;
}

.bottom-nav-item.active {
  color: var(--md-primary);
}

.bottom-nav-item.active .material-icons {
  color: var(--md-primary);
}

/* === App Container === */
#app-container {
  min-height: 100vh;
  padding: var(--md-spacing-md);
  padding-bottom: calc(var(--md-bottom-nav-height) + var(--md-spacing-md));
}

body.login-active #app-container {
  padding-bottom: var(--md-spacing-md);
  min-height: unset;
  height: 100vh;
  overflow: hidden;
}

.page {
  display: none;
}

.page.active {
  display: block;
}

#page-login.active {
  display: flex;
  height: 100%;
  overflow: hidden;
}

/* === Loading Screen === */
.loading-screen {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.95);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  gap: var(--md-spacing-md);
}

.loading-screen.hidden {
  display: none;
}

.loading-text {
  font-size: 0.875rem;
  color: var(--md-on-surface-variant);
}

/* === Card === */
.card {
  background: var(--md-surface);
  border-radius: var(--md-radius-md);
  padding: var(--md-spacing-md);
  box-shadow: var(--md-elevation-1);
  margin-bottom: var(--md-spacing-md);
}

/* === Home Grid === */
.home-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--md-spacing-md);
  margin-top: var(--md-spacing-md);
}

.home-action {
  min-height: 72px;
}

/* === Sections === */
.section-title {
  margin-bottom: var(--md-spacing-sm);
  font-size: 1rem;
  font-weight: 500;
}

/* === Photo List === */
.photo-list-horizontal {
  display: flex;
  gap: var(--md-spacing-sm);
  overflow-x: auto;
  padding: var(--md-spacing-sm) 0;
}

.photo-thumb {
  width: 100px;
  height: 100px;
  border-radius: var(--md-radius-sm);
  object-fit: cover;
  border: 2px solid transparent;
  cursor: pointer;
  transition: border-color 0.2s;
}

.photo-thumb.selected {
  border-color: var(--md-primary);
}

.photo-item {
  position: relative;
}

.photo-delete {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 50%;
  background: rgba(211, 47, 47, 0.9);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

/* === Badge === */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  border-radius: 12px;
  background: var(--md-primary);
  color: var(--md-on-primary);
  font-size: 0.8rem;
  padding: 0 8px;
}

/* === Status Badge === */
.status-badge {
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.75rem;
  font-weight: 600;
}

.status-ok {
  background: #e8f5e9;
  color: #2e7d32;
}

.status-ko {
  background: #ffebee;
  color: #c62828;
}

/* === Topbar (page-level, kept for compatibility) === */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--md-spacing-md);
}

/* === Actions Row === */
.actions-row {
  display: grid;
  gap: var(--md-spacing-sm);
  margin-top: var(--md-spacing-md);
}

/* === Login === */
#page-login {
  align-items: center;
  justify-content: center;
  padding: var(--md-spacing-md);
}

.login-card {
  background: var(--md-surface);
  border-radius: 20px;
  padding: 40px 36px 36px;
  box-shadow: var(--md-elevation-3);
  width: 100%;
  max-width: 380px;
}

.login-logo-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 28px;
}

.login-logo {
  width: 140px;
  height: auto;
  object-fit: contain;
  margin-bottom: 16px;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,0.12));
}

.login-app-name {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--md-primary);
  letter-spacing: 0.02em;
  text-align: center;
  line-height: 1.2;
}

.login-divider {
  height: 1px;
  background: var(--md-outline);
  margin: 0 0 20px;
}

/* === Responsive === */
@media (min-width: 768px) {
  #app-container {
    max-width: 900px;
    margin: 0 auto;
  }

  .home-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .app-bar-username {
    max-width: 200px;
  }
}

/* === DevExtreme dialog — margini laterali su mobile === */
@media (max-width: 600px) {
  .dx-dialog-wrapper .dx-overlay-content {
    left: 16px !important;
    right: 16px !important;
    width: auto !important;
    max-width: calc(100vw - 32px) !important;
    transform: none !important;
  }
}
