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

:root {
  /* HWU-Editor Light Theme Design System */
  --bg-main: #f1f5f9;
  --bg-panel: rgba(255, 255, 255, 0.88);
  --bg-input: #ffffff;
  --text-main: #0f172a;
  --text-muted: #475569;
  --text-dim: #94a3b8;
  --accent-primary: #0e7490;
  --accent-hover: #0c5f74;
  --accent-color-rgb: 14, 116, 144;
  --border-color: rgba(15, 23, 42, 0.12);
  --border-strong: rgba(15, 23, 42, 0.18);
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 10px;
  --glass-blur: blur(12px);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08), 0 4px 12px -2px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.15);
  --good: #10b981;
  --warn: #f59e0b;
  --btn-bg: var(--accent-primary);
  --btn-color: #ffffff;
  --btn-bg-hover: var(--accent-hover);
}

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

body {
  font-family: 'Inter', sans-serif;
  background-color: var(--bg-main);
  background-image:
    radial-gradient(at 0% 0%, rgba(var(--accent-color-rgb), 0.08) 0px, transparent 48%),
    radial-gradient(at 100% 100%, rgba(var(--accent-color-rgb), 0.05) 0px, transparent 46%);
  background-attachment: fixed;
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 2.5rem 1rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  scrollbar-gutter: stable;
}

.app-container {
  width: 100%;
  max-width: 540px;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* Header HWU-Editor Style */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 1.5rem;
  background: var(--bg-panel);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}


.brand-titles h1 {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--accent-primary);
  font-variant: all-small-caps;
  letter-spacing: 0.02em;
  line-height: 1.2;
}

.subtitle {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.status-pill {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-md);
  font-size: 0.78rem;
  font-weight: 500;
  background: rgba(15, 23, 42, 0.05);
  border: 1px solid var(--border-color);
}

.status-pill .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
}

.status-pill.active .dot {
  background-color: var(--good);
  box-shadow: 0 0 6px var(--good);
}

/* Network Info Banner */
.network-card {
  background: rgba(var(--accent-color-rgb), 0.06);
  border: 1px solid rgba(var(--accent-color-rgb), 0.2);
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
}

.network-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.url-badge {
  color: var(--accent-primary);
  font-weight: 600;
}

/* Glass Panel Card */
.card {
  background: var(--bg-panel);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 2rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  overflow: visible;
}

.card h2 {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-main);
  letter-spacing: -0.02em;
}

/* Input Wrapper */
.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.input-wrapper input {
  padding-right: 2.5rem;
}

.btn-clear {
  position: absolute;
  right: 0.75rem;
  background: rgba(15, 23, 42, 0.1);
  color: var(--text-muted);
  border: none;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 2;
  transition: all 0.15s ease;
}

.btn-clear:hover {
  background: rgba(225, 29, 72, 0.2);
  color: #e11d48;
}

/* Custom Floating Dropdown Menu */
.custom-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 4px;
  max-height: 240px;
  overflow-y: auto;
  background: #ffffff;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 100;
}

.dropdown-item {
  padding: 0.75rem 1rem;
  font-size: 0.92rem;
  color: var(--text-main);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(15, 23, 42, 0.05);
  transition: background 0.15s ease;
}

.dropdown-item:last-child {
  border-bottom: none;
}

.dropdown-item:hover, .dropdown-item.active {
  background: rgba(var(--accent-color-rgb), 0.1);
  color: var(--accent-hover);
  font-weight: 600;
}

.item-sheet-badge {
  font-size: 0.7rem;
  color: var(--text-muted);
  background: rgba(15, 23, 42, 0.06);
  padding: 0.15rem 0.45rem;
  border-radius: var(--radius-sm);
}

/* Category & Current Value Badge Box */
.category-badge-box {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.82rem;
  background: rgba(15, 23, 42, 0.04);
  padding: 0.6rem 0.85rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.category-label {
  color: var(--text-muted);
}

.badge-modello {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-sm);
  background: rgba(var(--accent-color-rgb), 0.12);
  color: var(--accent-hover);
  border: 1px solid rgba(var(--accent-color-rgb), 0.3);
}

.current-val-tag {
  margin-left: auto;
  font-weight: 600;
  color: var(--accent-primary);
}

/* Editable Minutes Row */
.minutes-edit-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.minutes-edit-row input {
  flex: 1;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent-primary);
}

.time-tag {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--good);
  background: rgba(16, 185, 129, 0.12);
  padding: 0.4rem 0.85rem;
  border-radius: var(--radius-md);
  border: 1px solid rgba(16, 185, 129, 0.3);
  white-space: nowrap;
}

/* Battery Extrapolation Sub-Box */
.battery-extrapolate-subcard {
  margin-top: 0.75rem;
  background: rgba(245, 158, 11, 0.06);
  border: 1px solid rgba(245, 158, 11, 0.25);
  border-radius: var(--radius-md);
  padding: 0.85rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.subcard-header label {
  font-size: 0.8rem;
  font-weight: 600;
  color: #b45309;
}

.pct-input-row {
  display: flex;
  gap: 0.5rem;
}

.pct-input-row input {
  flex: 1;
  padding: 0.55rem 0.75rem;
  font-size: 0.9rem;
}

.btn-secondary-sm {
  background: var(--accent-primary);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-md);
  padding: 0.55rem 0.9rem;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease;
}

.btn-secondary-sm:hover {
  background: var(--accent-hover);
}

.extrapolation-formula-meta {
  font-size: 0.78rem;
  color: #92400e;
  font-weight: 500;
}

.log-calc-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

/* Form Controls HWU-Editor Style */
.form-group {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
}

input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  border-radius: var(--radius-md);
  padding: 0.85rem 1rem;
  font-family: inherit;
  font-size: 1rem;
  transition: all 0.2s ease;
}

input:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(var(--accent-color-rgb), 0.2);
}

/* Primary Action Button HWU-Editor Style */
.btn-primary-big {
  width: 100%;
  padding: 1rem 1.5rem;
  background: var(--btn-bg);
  color: var(--btn-color);
  border: none;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  box-shadow: 0 4px 14px 0 rgba(var(--accent-color-rgb), 0.35);
}

.btn-primary-big:hover {
  background: var(--btn-bg-hover);
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(var(--accent-color-rgb), 0.25);
}

.btn-primary-big:active {
  transform: translateY(1px);
}

.btn-primary-big:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* Result Card */
.result-card-success {
  background: rgba(16, 185, 129, 0.08);
  border: 1px solid rgba(16, 185, 129, 0.3);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  animation: fadeIn 0.3s ease;
}

.result-card-success h3 {
  color: #047857;
  font-size: 1.05rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.result-big-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--good);
  line-height: 1;
}

.result-meta {
  font-size: 0.85rem;
  color: #065f46;
  line-height: 1.5;
}

/* Stato storage in errore */
.status-pill.danger .dot {
  background-color: #ef4444;
  box-shadow: 0 0 6px #ef4444;
}

/* Striscia stato backup */
.backup-strip {
  font-size: 0.75rem;
  color: var(--text-muted);
  background: rgba(15, 23, 42, 0.04);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.5rem 0.85rem;
}

.backup-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.backup-toggle {
  background: none;
  border: none;
  color: var(--accent-primary);
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  white-space: nowrap;
  text-decoration: underline;
}

.backup-toggle:hover {
  color: var(--accent-hover);
}

/* Pannello elenco copie */
.backup-panel {
  background: var(--bg-panel);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  animation: fadeIn 0.25s ease;
}

.backup-panel-hint,
.backup-more,
.backup-empty {
  font-size: 0.73rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.backup-list {
  display: flex;
  flex-direction: column;
  max-height: 320px;
  overflow-y: auto;
}

.backup-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid rgba(15, 23, 42, 0.06);
}

.backup-row:last-child {
  border-bottom: none;
}

.backup-info {
  display: flex;
  flex-direction: column;
  gap: 0.05rem;
  min-width: 0;
  flex: 1;
}

.backup-when {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-main);
}

.backup-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.backup-size {
  font-size: 0.72rem;
  color: var(--text-dim);
  white-space: nowrap;
}

.backup-download {
  font-size: 0.75rem;
  font-weight: 600;
  color: #ffffff;
  background: var(--accent-primary);
  padding: 0.35rem 0.7rem;
  border-radius: var(--radius-sm);
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.15s ease;
}

.backup-download:hover {
  background: var(--accent-hover);
}

/* Ripristino: volutamente meno invitante del download, e con un passaggio
   di conferma prima di fare qualcosa. */
.backup-restore {
  font-size: 0.75rem;
  font-weight: 600;
  color: #b45309;
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.35);
  padding: 0.33rem 0.7rem;
  border-radius: var(--radius-sm);
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.backup-restore:hover {
  background: rgba(245, 158, 11, 0.22);
}

.backup-restore:disabled {
  opacity: 0.6;
  cursor: wait;
}

.backup-confirm {
  flex-direction: column;
  align-items: stretch;
  gap: 0.6rem;
  background: rgba(245, 158, 11, 0.08);
  border: 1px solid rgba(245, 158, 11, 0.35);
  border-radius: var(--radius-md);
  padding: 0.75rem 0.85rem;
  margin: 0.25rem 0;
}

.backup-confirm-text {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.78rem;
  line-height: 1.45;
  color: #92400e;
}

.backup-confirm-actions {
  display: flex;
  gap: 0.5rem;
}

.backup-restore.confirm-yes {
  background: #b45309;
  color: #ffffff;
  border-color: #b45309;
}

.backup-restore.confirm-yes:hover {
  background: #92400e;
}

.backup-cancel {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  background: #ffffff;
  border: 1px solid var(--border-color);
  padding: 0.33rem 0.7rem;
  border-radius: var(--radius-sm);
  font-family: inherit;
  cursor: pointer;
}

.backup-cancel:hover {
  border-color: var(--border-strong);
  color: var(--text-main);
}

.backup-strip.empty {
  color: #92400e;
  background: rgba(245, 158, 11, 0.08);
  border-color: rgba(245, 158, 11, 0.3);
}

/* Avvisi */
.alert-box {
  font-size: 0.85rem;
  font-weight: 500;
  line-height: 1.45;
  padding: 0.85rem 1rem;
  border-radius: var(--radius-md);
  animation: fadeIn 0.25s ease;
}

.alert-warn {
  color: #92400e;
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.35);
}

.alert-danger {
  color: #9f1239;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.35);
}

/* Scelta esplicita del bersaglio */
.candidate-box {
  background: rgba(245, 158, 11, 0.06);
  border: 1px solid rgba(245, 158, 11, 0.3);
  border-radius: var(--radius-md);
  padding: 0.85rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.candidate-title {
  font-size: 0.82rem;
  font-weight: 600;
  color: #b45309;
}

.candidate-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.candidate-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  width: 100%;
  text-align: left;
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.75rem;
  font-family: inherit;
  font-size: 0.85rem;
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.15s ease;
}

.candidate-item:hover {
  border-color: var(--accent-primary);
  background: rgba(var(--accent-color-rgb), 0.06);
}

.candidate-main {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
}

.candidate-name {
  font-weight: 600;
}

.candidate-loc {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.candidate-current {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent-primary);
  white-space: nowrap;
}

.candidate-create {
  justify-content: center;
  font-weight: 600;
  color: var(--accent-primary);
  border-style: dashed;
}

/* Creazione riga nuova */
.create-box {
  background: rgba(var(--accent-color-rgb), 0.06);
  border: 1px solid rgba(var(--accent-color-rgb), 0.25);
  border-radius: var(--radius-md);
  padding: 0.85rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.create-title {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--accent-hover);
}

.create-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.create-row label {
  min-width: 110px;
}

.create-row input,
.create-row select {
  flex: 1;
  padding: 0.55rem 0.75rem;
  font-size: 0.9rem;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-family: inherit;
  color: var(--text-main);
}

.create-hint {
  font-size: 0.73rem;
  color: var(--text-muted);
}

.result-meta div {
  margin-bottom: 0.15rem;
}

.hidden {
  display: none !important;
}

.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: #0f172a;
  color: #ffffff;
  padding: 0.75rem 1.5rem;
  border-radius: 30px;
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: 0 10px 25px rgba(0,0,0,0.2);
  z-index: 1000;
}

.toast.error {
  background: #ef4444;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Login Page Styles */
.login-body {
  align-items: center;
}

.login-container {
  max-width: 440px;
  margin: auto;
}

.login-header {
  justify-content: center;
  text-align: center;
}

.login-intro {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 1.25rem;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.login-form input {
  width: 100%;
  padding: 0.75rem 1rem;
  font-size: 0.95rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background-color: var(--bg-input);
  color: var(--text-main);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.login-form input:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(var(--accent-color-rgb), 0.15);
}

.login-footer {
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-top: 0.5rem;
}

.logout-link {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-decoration: none;
  padding: 0.3rem 0.65rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.logout-link:hover {
  background: rgba(239, 68, 68, 0.08);
  color: #ef4444;
  border-color: rgba(239, 68, 68, 0.2);
}

