/* ============================================
   TI_StockConnect — Design System
   ============================================ */

:root {
  /* Brand */
  --ti-blue: #1B4D89;
  --ti-blue-deep: #0E2E54;
  --ti-blue-soft: #2E6BB0;
  --ti-blue-bar: #1B4D89;
  --ti-accent: #B73A4A;       /* section header red (refined from original) */
  --ti-accent-soft: #E8C5CB;

  /* Surfaces */
  --bg: #F4F6FA;
  --bg-alt: #EEF1F7;
  --surface: #FFFFFF;
  --surface-2: #F9FAFC;
  --surface-hover: #F2F5FA;
  --border: #E1E6EE;
  --border-strong: #C9D1DE;

  /* Text */
  --text: #1C2434;
  --text-2: #4A5468;
  --text-3: #79839A;
  --text-on-blue: #FFFFFF;

  /* Status */
  --ok: #2D8A5F;
  --ok-soft: #E1F2EA;
  --warn: #C68A26;
  --warn-soft: #FBF1DE;
  --err: #C0392B;
  --err-soft: #FBE5E2;
  --info: #2E6BB0;
  --info-soft: #E1ECF7;

  /* Spacing scale */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 24px;
  --s-6: 32px;
  --s-7: 48px;

  /* Radius */
  --r-1: 3px;
  --r-2: 6px;
  --r-3: 10px;

  /* Shadow */
  --shadow-1: 0 1px 2px rgba(14, 46, 84, 0.06);
  --shadow-2: 0 4px 14px rgba(14, 46, 84, 0.08);
  --shadow-3: 0 10px 40px rgba(14, 46, 84, 0.18);

  /* Type */
  --font-sans: Tahoma, Geneva, Verdana, sans-serif;
  --font-mono: Tahoma, Geneva, Verdana, sans-serif;
}

* { box-sizing: border-box; }

/* ============================================
   Dark theme
   ============================================ */
body.dark {
  --bg: #0F1620;
  --bg-alt: #18212E;
  --surface: #161E2A;
  --surface-2: #1B2533;
  --surface-hover: #1F2B3B;
  --border: #2A3648;
  --border-strong: #3A4759;

  --text: #E6ECF3;
  --text-2: #B4BFCC;
  --text-3: #7E8C9E;

  --ti-blue: #6FA8FF;
  --ti-blue-deep: #4F90F0;
  --ti-blue-soft: #2A4A78;
  --ti-blue-bar: #1B2533;

  --ti-accent: #FF7989;
  --ti-accent-soft: #4A2730;

  --ok: #4FCB8C; --ok-soft: #1A3328;
  --warn: #E5B547; --warn-soft: #3A2E15;
  --err: #F47267; --err-soft: #3D1F1B;
  --info: #6FA8FF; --info-soft: #1F2E47;

  --shadow-1: 0 1px 2px rgba(0,0,0,0.4);
  --shadow-2: 0 4px 14px rgba(0,0,0,0.4);
  --shadow-3: 0 10px 40px rgba(0,0,0,0.6);
}
body.dark .login-card { background: rgba(22,30,42,0.97); }
body.dark .pagination .total .label { background: #5A4612; color: #FFD96B; }
body.dark .product-name { color: var(--text); }
body.dark .top-nav .nav-exit { background: var(--surface); color: var(--ti-blue); }

/* Direction: warm-minimal (rosso più sobrio, blu profondo) */
body.dir-warm {
  --ti-blue: #2D3F5E;
  --ti-blue-deep: #1A2740;
  --ti-blue-bar: #2D3F5E;
  --ti-accent: #C2492A;
}
body.dark.dir-warm { --ti-blue: #E0A878; --ti-accent: #F09A6E; --ti-blue-bar: #1B2533; }

/* Direction: green-ops (verde operativo, più SaaS moderno) */
body.dir-green {
  --ti-blue: #0B7A57;
  --ti-blue-deep: #075C42;
  --ti-blue-bar: #0B7A57;
  --ti-accent: #C4392B;
}
body.dark.dir-green { --ti-blue: #5FE0A8; --ti-accent: #F47267; --ti-blue-bar: #1B2533; }


html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

a { color: var(--ti-blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ============================================
   App shell
   ============================================ */
.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.app-header-inner {
  max-width: 1600px;
  margin: 0 auto;
  padding: 12px 28px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
}

.app-header .brand-left {
  display: flex;
  align-items: center;
}

.producer-product {
  display: flex;
  align-items: center;
  gap: 16px;
}

.ti-logo-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.ti-logo-img {
  height: 18px;
  width: auto;
}

.ti-version {
  font-size: 8px;
  color: var(--text-3);
  opacity: 0.6;
  margin-top: 2px;
}

.product {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-left: 16px;
  border-left: 1px solid var(--border);
}

.product-mark {
  width: 16px; height: 16px;
  background: var(--ti-blue);
  clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
}

.product-name {
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.02em;
  color: var(--text);
}

.brand-center {
  display: flex;
  justify-content: center;
  align-items: center;
}

.client-logo-img {
  max-height: 36px;
  max-width: 180px;
  object-fit: contain;
}

.client-logo-placeholder {
  padding: 6px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  background: var(--bg-2);
  border-radius: var(--r-2);
}

.brand-right {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 14px;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 6px 6px;
  border-radius: var(--r-3);
}
.user-chip:hover { background: var(--surface-hover); }
.user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--ti-blue);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 12px;
}
.user-meta { display: flex; flex-direction: column; line-height: 1.15; }
.user-meta .name { font-weight: 600; font-size: 13px; }
.user-meta .role { font-size: 11px; color: var(--text-3); }

/* Language Selector */
.lang-selector {
  position: relative;
}
.lang-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--r-2);
  background: var(--surface);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  transition: all 0.15s ease;
}
.lang-btn:hover {
  background: var(--surface-hover);
  border-color: var(--border-strong);
}
.lang-icon {
  display: flex;
  align-items: center;
}
.lang-icon svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  stroke-width: 1.5;
  fill: none;
}
.lang-code {
  font-size: 11px;
  letter-spacing: 0.05em;
}
.lang-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  min-width: 140px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-2);
  box-shadow: var(--shadow-2);
  z-index: 1000;
  overflow: hidden;
}
.lang-option {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 14px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  text-align: left;
  transition: background 0.1s;
}
.lang-option:hover {
  background: var(--surface-hover);
}
.lang-option.active {
  background: var(--info-soft);
  color: var(--ti-blue);
  font-weight: 600;
}
.lang-option-flag {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-3);
  min-width: 22px;
}
.lang-option.active .lang-option-flag {
  color: var(--ti-blue);
}
.lang-option-name {
  flex: 1;
}

/* Role switcher (demo) */
.role-switcher {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-alt);
  border-radius: 999px;
  padding: 3px;
}
.role-switcher .label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-3);
  padding: 0 8px 0 10px;
  font-weight: 600;
}
.role-switcher button {
  font-size: 12px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 999px;
  color: var(--text-2);
}
.role-switcher button.active {
  background: var(--ti-blue);
  color: white;
  box-shadow: var(--shadow-1);
}

/* Top nav */
.top-nav {
  background: var(--ti-blue-bar);
  color: white;
}
.top-nav-inner {
  max-width: 1600px;
  margin: 0 auto;
  padding: 0 28px;
  display: flex;
  align-items: stretch;
  gap: 4px;
}
.top-nav .nav-item {
  padding: 14px 22px;
  font-size: 14px;
  font-weight: 500;
  color: rgba(255,255,255,0.78);
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  letter-spacing: 0.01em;
}
.top-nav .nav-item:first-child { padding-left: 0; }
.top-nav .nav-item:hover { color: white; }
.top-nav .nav-item.active {
  color: white;
  font-weight: 700;
}
.top-nav .nav-item.active::after {
  content: "";
  position: absolute;
  left: 14px; right: 14px; bottom: 0;
  height: 3px;
  background: white;
}
.top-nav .nav-item:first-child.active::after { left: 0; }
.top-nav .nav-spacer { flex: 1; }
.top-nav .nav-exit {
  align-self: center;
  margin-right: 6px;
  background: rgba(255,255,255,0.95);
  color: var(--ti-blue);
  padding: 7px 22px;
  border-radius: var(--r-2);
  font-weight: 600;
  font-size: 13px;
}
.top-nav .nav-exit:hover { background: white; }

/* Main */
.app-main {
  flex: 1;
  padding: 24px 28px 40px;
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
}

/* Section heading (red, like original) */
.section-h {
  color: var(--ti-accent);
  font-size: 18px;
  font-weight: 700;
  margin: 0 0 14px;
  letter-spacing: -0.005em;
}
.section-h .sub {
  font-weight: 400;
  font-size: 13px;
  color: var(--text-3);
  margin-left: 10px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-2);
  box-shadow: var(--shadow-1);
}
.panel + .panel { margin-top: 20px; }
.panel-body { padding: 20px 22px; }
.panel-header {
  padding: 14px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.panel-header h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

/* Forms */
.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px 20px;
  align-items: end;
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
}
.field input[type=text],
.field input[type=password],
.field input[type=email],
.field input[type=number],
.field select,
.field textarea {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-1);
  padding: 8px 10px;
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--ti-blue);
  box-shadow: 0 0 0 3px rgba(27,77,137,0.12);
}

.checkbox {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  user-select: none;
}
.checkbox input { position: absolute; opacity: 0; pointer-events: none; }
.checkbox .box {
  width: 16px; height: 16px;
  border: 1.5px solid var(--border-strong);
  border-radius: 3px;
  background: var(--surface);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.checkbox input:checked + .box {
  background: var(--ti-blue);
  border-color: var(--ti-blue);
}
.checkbox input:checked + .box::after {
  content: "";
  width: 9px; height: 5px;
  border-left: 2px solid white;
  border-bottom: 2px solid white;
  transform: rotate(-45deg) translate(1px, -1px);
}

/* Toggle switch */
.toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle .switch {
  position: relative;
  width: 34px; height: 20px;
  background: var(--border-strong);
  border-radius: 999px;
  transition: background 0.18s;
  flex-shrink: 0;
}
.toggle .switch::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: white;
  transition: transform 0.18s;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
.toggle input:checked + .switch { background: var(--ti-blue); }
.toggle input:checked + .switch::after { transform: translateX(14px); }
.toggle .toggle-label { font-size: 13px; color: var(--text); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 18px;
  border-radius: var(--r-1);
  font-size: 13px;
  font-weight: 600;
  transition: all 0.15s;
  border: 1px solid transparent;
  white-space: nowrap;
}
.btn-primary {
  background: var(--ti-blue);
  color: white;
}
.btn-primary:hover { background: var(--ti-blue-deep); }
.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}
.btn-secondary:hover { background: var(--surface-hover); border-color: var(--text-3); }
.btn-ghost {
  background: transparent;
  color: var(--ti-blue);
}
.btn-ghost:hover { background: var(--info-soft); }
.btn-danger {
  background: var(--err);
  color: white;
}
.btn-danger:hover { background: #9d2e22; }

/* Export button - green accent */
.btn-export {
  background: linear-gradient(135deg, #059669 0%, #047857 100%);
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 2px 8px rgba(5, 150, 105, 0.3);
  transition: all 0.2s ease;
}
.btn-export:hover {
  background: linear-gradient(135deg, #047857 0%, #065f46 100%);
  box-shadow: 0 4px 12px rgba(5, 150, 105, 0.4);
  transform: translateY(-1px);
}
.btn-export:active {
  transform: translateY(0);
  box-shadow: 0 2px 6px rgba(5, 150, 105, 0.3);
}
.btn-export:disabled {
  background: var(--border);
  color: var(--text-3);
  box-shadow: none;
  cursor: not-allowed;
  transform: none;
}
.btn-export .btn-export-icon {
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-export .btn-export-icon svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
}
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-lg { padding: 11px 26px; font-size: 14px; }

/* Filter Panel */
.filter-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-3);
  overflow: hidden;
  box-shadow: var(--shadow-1);
}
.filter-panel-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 20px;
  background: linear-gradient(135deg, var(--ti-blue) 0%, var(--ti-blue-deep) 100%);
  color: white;
  font-weight: 600;
  font-size: 14px;
}
.filter-panel-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: rgba(255,255,255,0.2);
  border-radius: 6px;
}
.filter-panel-icon svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
}
.filter-panel-body {
  padding: 20px;
}
.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}
.filter-grid .field {
  margin: 0;
}
.filter-grid .field label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-3);
  margin-bottom: 6px;
}
.filter-grid .field input,
.filter-grid .field select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-2);
  font-size: 13px;
  background: var(--surface);
  transition: all 0.15s;
}
.filter-grid .field input:focus,
.filter-grid .field select:focus {
  border-color: var(--ti-blue);
  box-shadow: 0 0 0 3px rgba(27, 77, 137, 0.1);
  outline: none;
}
.filter-grid .field input[type="date"] {
  cursor: pointer;
}
.filter-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  align-items: center;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
body.dark .filter-panel-header {
  background: linear-gradient(135deg, var(--ti-blue-soft) 0%, #1a3a5c 100%);
}
body.dark .filter-grid .field input:focus,
body.dark .filter-grid .field select:focus {
  box-shadow: 0 0 0 3px rgba(111, 168, 255, 0.15);
}

/* Tables */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-2);
  overflow: hidden;
}
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.data thead th {
  text-align: left;
  font-weight: 600;
  color: var(--text-2);
  padding: 12px 16px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  position: sticky;
  top: 0;
}
table.data thead th.num { text-align: right; }
table.data tbody td {
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}
table.data tbody td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tbody td.mono { font-family: var(--font-mono); font-size: 12.5px; }
table.data tbody tr:last-child td { border-bottom: none; }
table.data tbody tr:hover { background: var(--surface-hover); }
table.data tbody tr.clickable { cursor: pointer; }

.row-actions {
  display: inline-flex;
  gap: 4px;
}
.row-actions button {
  padding: 4px 8px;
  font-size: 11px;
  border-radius: var(--r-1);
  color: var(--ti-blue);
}
.row-actions button:hover { background: var(--info-soft); }
.row-actions button.danger { color: var(--err); }
.row-actions button.danger:hover { background: var(--err-soft); }

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--surface-2);
  border-top: 1px solid var(--border);
  font-size: 13px;
}
.pagination .pages { display: flex; gap: 2px; align-items: center; }
.pagination .pages button {
  width: 28px; height: 28px;
  border-radius: var(--r-1);
  font-size: 13px;
  color: var(--ti-blue);
  font-weight: 500;
}
.pagination .pages button:hover { background: var(--info-soft); }
.pagination .pages button.active { background: var(--ti-blue); color: white; }
.pagination .total {
  display: flex; align-items: center; gap: 10px;
  font-size: 13px;
}
.pagination .total .label {
  background: #FFF59A;
  padding: 2px 8px;
  font-weight: 700;
  color: var(--ti-accent);
  border-radius: 2px;
}
.pagination .total .value {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  padding: 4px 14px;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-family: var(--font-mono);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.err { background: var(--err-soft); color: var(--err); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.neutral { background: var(--bg-alt); color: var(--text-2); }
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* Segno dot for movements */
.segno-dot {
  display: inline-block;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background-size: 14px 14px;
  background-position: center;
  background-repeat: no-repeat;
  vertical-align: middle;
  margin: 0 auto;
}
.segno-dot.plus {
  background-color: var(--ok);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round'%3E%3Cpath d='M12 5v14M5 12h14'/%3E%3C/svg%3E");
}
.segno-dot.minus {
  background-color: var(--err);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round'%3E%3Cpath d='M5 12h14'/%3E%3C/svg%3E");
}

/* Stat cards */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-2);
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: var(--accent-color, var(--ti-blue));
}
.stat-card .stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-bg, var(--info-soft));
  color: var(--accent-color, var(--ti-blue));
  flex-shrink: 0;
}
.stat-card .stat-icon svg {
  width: 24px;
  height: 24px;
  stroke-width: 2;
  stroke: currentColor;
  fill: none;
}
.stat-card .stat-content {
  flex: 1;
  min-width: 0;
}
.stat-card .label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
  font-weight: 600;
  margin-bottom: 2px;
}
.stat-card .value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  line-height: 1.1;
}
.stat-card .delta {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 2px;
}
.stat-card .delta.up { color: var(--ok); }
.stat-card .delta.down { color: var(--err); }

/* Stat card color accents */
.stat-card.accent-blue {
  --accent-color: #2563eb;
  --accent-bg: #eff6ff;
}
.stat-card.accent-green {
  --accent-color: #16a34a;
  --accent-bg: #f0fdf4;
}
.stat-card.accent-purple {
  --accent-color: #7c3aed;
  --accent-bg: #f5f3ff;
}
.stat-card.accent-orange {
  --accent-color: #ea580c;
  --accent-bg: #fff7ed;
}
body.dark .stat-card.accent-blue { --accent-bg: #1e3a5f; }
body.dark .stat-card.accent-green { --accent-bg: #14412a; }
body.dark .stat-card.accent-purple { --accent-bg: #2e1a5e; }
body.dark .stat-card.accent-orange { --accent-bg: #4a2512; }

/* Cards (C2 list etc) */
.c2-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}
.c2-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-2);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  transition: all 0.15s;
}
.c2-card:hover { border-color: var(--ti-blue); box-shadow: var(--shadow-2); }
.c2-card .top { display: flex; justify-content: space-between; align-items: flex-start; }
.c2-card .name { font-weight: 700; font-size: 15px; }
.c2-card .id { font-family: var(--font-mono); font-size: 11px; color: var(--text-3); }
.c2-card .stats-row {
  display: flex; gap: 18px;
  padding-top: 12px; border-top: 1px solid var(--border);
}
.c2-card .stats-row .stat {
  display: flex; flex-direction: column; gap: 2px;
}
.c2-card .stats-row .stat .l { font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-3); font-weight: 600; }
.c2-card .stats-row .stat .v { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* Drawer / modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(14, 46, 84, 0.32);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 24px;
  animation: fadeIn 0.15s ease-out;
}
.modal {
  background: var(--surface);
  border-radius: var(--r-2);
  box-shadow: var(--shadow-3);
  max-width: 560px;
  width: 100%;
  max-height: 88vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: scaleIn 0.18s ease-out;
}
.modal-lg { max-width: 820px; }
.modal-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-header h2 { margin: 0; font-size: 16px; color: var(--ti-accent); }
.modal-header .close { font-size: 20px; color: var(--text-3); padding: 0 6px; line-height: 1; }
.modal-header .close:hover { color: var(--text); }
.modal-body { padding: 22px; overflow: auto; flex: 1; }
.modal-footer {
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  background: var(--surface-2);
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes scaleIn { from { opacity: 0; transform: scale(0.97); } to { opacity: 1; transform: scale(1); } }

/* Filter bar */
.filter-bar {
  display: grid;
  grid-template-columns: 1.2fr 2fr 1fr auto auto;
  gap: 14px;
  align-items: end;
}

/* Empty state */
.empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-3);
}
.empty .icon { font-size: 32px; opacity: 0.4; margin-bottom: 8px; }

/* Login */
.login-page {
  min-height: 100vh;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: linear-gradient(135deg, #0E2E54 0%, #1B4D89 50%, #2E6BB0 100%);
}
.login-page::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(circle at 20% 30%, rgba(255,255,255,0.06) 0, transparent 40%),
    radial-gradient(circle at 80% 70%, rgba(255,255,255,0.04) 0, transparent 35%);
}
.login-page .grid-bg {
  position: absolute; inset: 0;
  background-image:
    linear-gradient(to right, rgba(255,255,255,0.04) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255,255,255,0.04) 1px, transparent 1px);
  background-size: 60px 60px;
  mask-image: radial-gradient(ellipse at center, black 30%, transparent 75%);
}
.login-lines { position: absolute; inset: 0; pointer-events: none; opacity: 0.4; }
.login-card {
  position: relative;
  z-index: 2;
  background: rgba(255,255,255,0.97);
  border-radius: var(--r-3);
  padding: 36px 40px 32px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 30px 80px rgba(0,0,0,0.3);
  backdrop-filter: blur(8px);
}
.login-tenant {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}
.login-tenant .mark { display: flex; align-items: center; gap: 8px; }
.login-tenant .mark .diamond { width: 18px; height: 18px; background: var(--ti-blue); clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%); }
.login-tenant .mark .name { font-weight: 600; font-size: 14px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text); }
.login-tenant .mark .name .accent { color: var(--text-3); font-weight: 400; }
.login-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 24px;
  text-align: center;
}
.login-card .field input { padding: 11px 14px; font-size: 14px; }
.login-card .btn { width: 100%; padding: 12px; font-size: 14px; }
.login-meta {
  margin-top: 20px;
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-3);
}
.login-meta a { color: var(--ti-blue); }

/* Login Language Selector */
.login-lang-selector {
  position: absolute;
  top: 12px;
  right: 12px;
}

.login-footer-mark {
  position: absolute;
  bottom: 24px;
  left: 28px;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 2px;
  color: rgba(255,255,255,0.7);
}
.login-footer-mark .ti-logo { color: white; font-size: 14px; font-weight: 700; }
.login-footer-mark .ti-logo .ti-i { color: #7AB7FF; }
.login-footer-mark .small { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; }

/* Switch tabs (sub-nav) */
.subtabs {
  display: inline-flex;
  background: var(--bg-alt);
  border-radius: var(--r-2);
  padding: 3px;
  margin-bottom: 16px;
}
.subtabs button {
  padding: 7px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  border-radius: 5px;
}
.subtabs button.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-1);
  font-weight: 600;
}

/* Inline icons */
.icon {
  display: inline-flex;
  width: 16px; height: 16px;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
}
.icon svg { width: 100%; height: 100%; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* Toolbar */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
  flex-wrap: wrap;
}
.toolbar .left, .toolbar .right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* Settings list */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
  gap: 20px;
}
.setting-row:last-child { border-bottom: none; }
.setting-row .left { flex: 1; }
.setting-row .title { font-weight: 600; font-size: 13.5px; }
.setting-row .desc { font-size: 12.5px; color: var(--text-3); margin-top: 2px; }

/* Sparkline placeholder */
.spark {
  height: 32px;
  width: 100%;
  background: linear-gradient(180deg, var(--info-soft) 0%, transparent 100%);
  position: relative;
  overflow: hidden;
  border-radius: 3px;
}
.spark svg { width: 100%; height: 100%; display: block; }

/* Movement type pill */
.mvt-in { color: var(--ok); font-weight: 600; }
.mvt-out { color: var(--err); font-weight: 600; }

/* Excel export */
.export-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--ti-blue);
  font-size: 13px;
  font-weight: 500;
}
.export-link:hover { text-decoration: underline; }

/* 2FA panel */
.twofa-card {
  background: linear-gradient(135deg, var(--info-soft), var(--surface));
  border: 1px solid var(--ti-blue-soft);
  border-radius: var(--r-2);
  padding: 18px;
}

/* Log entries */
.log-entry {
  display: grid;
  grid-template-columns: 130px 80px 1fr auto;
  gap: 14px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  align-items: center;
  font-size: 13px;
}
.log-entry:hover { background: var(--surface-hover); }
.log-entry .ts { font-family: var(--font-mono); font-size: 11.5px; color: var(--text-3); }
.log-entry .msg { color: var(--text-2); }

/* Tenant strip (admin) */
.tenant-strip {
  display: flex;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  gap: 14px;
}
.tenant-strip:last-child { border-bottom: none; }
.tenant-strip:hover { background: var(--surface-hover); }
.tenant-strip .tmark {
  width: 38px; height: 38px;
  border-radius: var(--r-2);
  background: var(--ti-blue);
  color: white;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px;
  font-family: var(--font-mono);
}
.tenant-strip .info { flex: 1; }
.tenant-strip .info .nm { font-weight: 600; font-size: 14px; }
.tenant-strip .info .sub { font-size: 12px; color: var(--text-3); }
.tenant-strip .info .sub .sep { margin: 0 8px; color: var(--border-strong); }
.tenant-strip .quota {
  display: flex; align-items: center; gap: 10px;
}
.quota-bar {
  width: 110px; height: 6px;
  background: var(--bg-alt);
  border-radius: 999px;
  overflow: hidden;
}
.quota-bar .fill {
  height: 100%;
  background: var(--ti-blue);
  transition: width 0.3s;
}
.quota-bar .fill.full { background: var(--warn); }
.quota-bar .fill.over { background: var(--err); }

/* Helper utils */
.muted { color: var(--text-3); }
.mono { font-family: var(--font-mono); }
.right { text-align: right; }
.center { text-align: center; }
.flex { display: flex; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; }
.mb-16 { margin-bottom: 16px; }
.w-full { width: 100%; }

/* Quota chip */
.api-key {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 6px 10px;
  border-radius: var(--r-1);
  font-family: var(--font-mono);
  font-size: 12px;
}
.api-key .copy { color: var(--ti-blue); font-weight: 600; padding: 0 4px; }

/* Stats Cards - Summary cards for Saldi */
.stats-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}
.stats-cards.stats-cards-4 {
  grid-template-columns: repeat(4, 1fr);
}
@media (max-width: 1100px) {
  .stats-cards.stats-cards-4 {
    grid-template-columns: repeat(2, 1fr);
  }
}
@media (max-width: 900px) {
  .stats-cards {
    grid-template-columns: 1fr;
  }
  .stats-cards.stats-cards-4 {
    grid-template-columns: 1fr;
  }
}

.stats-cards .stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-2);
  padding: 16px 20px;
  display: flex;
  align-items: flex-start;
  gap: 14px;
  position: relative;
}

.stat-card-icon {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.stat-card-icon svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.stat-card-content {
  flex: 1;
  min-width: 0;
}

.stat-card-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-3);
  font-weight: 600;
  margin-bottom: 4px;
}

.stat-card-value {
  font-size: 32px;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.stat-card-sub {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 2px;
}

.stat-card-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-card-list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.stat-card-list-label {
  font-size: 13px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 140px;
}

.stat-card-list-value {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.stat-card-list-value small {
  font-weight: 400;
  font-size: 11px;
  color: var(--text-3);
  margin-left: 2px;
}

.stat-card-bar {
  position: absolute;
  left: 0;
  top: 12px;
  bottom: 12px;
  width: 4px;
  background: var(--primary, #7c3aed);
  border-radius: 0 2px 2px 0;
}

/* Sparkline for movement cards */
.stat-card-sparkline {
  position: absolute;
  bottom: 12px;
  right: 16px;
  width: 100px;
  height: 30px;
}
.stat-card-sparkline svg {
  width: 100%;
  height: 100%;
}
.stat-card-sparkline.green {
  color: var(--ok);
}
.stat-card-sparkline.red {
  color: var(--err);
}

/* Paginazione */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}
.pagination button {
  min-width: 32px;
}
.pagination-info {
  font-size: 13px;
  color: var(--text-2);
  padding: 0 12px;
}

/* Filter actions inline */
.filter-actions-inline {
  flex: 0 0 auto;
  margin-left: auto;
}
