/* =============================================================================
   GEMMA ERP — Custom Theme
   Bootstrap 4 base + enterprise-style overrides
   ============================================================================= */

/* -----------------------------------------------------------------------------
   1. VARIABLES & RESET
   ----------------------------------------------------------------------------- */

:root {
  --sidebar-width: 240px;
  --header-height: 140px;
  --sidebar-bg: #1a3a5c;
  --sidebar-text: #c8d6e5;
  --sidebar-text-muted: #7a99b8;
  --sidebar-active-bg: #2e7d9e;
  --sidebar-active-text: #ffffff;
  --sidebar-hover-bg: rgba(255,255,255,0.06);
  --sidebar-border: rgba(255,255,255,0.08);
  --sidebar-section-label: #5a7fa0;
  --header-bg: #ffffff;
  --header-border: #e2e8f0;
  --content-bg: #f4f6f9;
  --card-bg: #ffffff;
  --card-border: #e2e8f0;
  --text-primary: #2d3748;
  --text-secondary: #4a5568;
  --text-muted: #718096;
  --accent: #2e7d9e;
  --accent-dark: #236282;
  --accent-light: #e8f4f8;
  --success: #2f855a;
  --danger: #c53030;
  --warning: #b7791f;
  --table-border: #e2e8f0;
  --table-hover: #f0f5fb;
  --table-header-bg: #f7fafc;
  --input-border: #cbd5e0;
  --input-focus: #2e7d9e;
  --border-radius: 4px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 2px 8px rgba(0,0,0,0.10);
}

*, *::before, *::after { box-sizing: border-box; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  color: var(--text-primary);
  background: var(--content-bg);
  margin: 0;
  padding: 0;
  line-height: 1.5;
}

/* -----------------------------------------------------------------------------
   2. LAYOUT SHELL
   ----------------------------------------------------------------------------- */

.erp-wrapper {
  display: flex;
  min-height: 100vh;
}

/* main content area (right of sidebar) */
.erp-main {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* -----------------------------------------------------------------------------
   3. SIDEBAR
   ----------------------------------------------------------------------------- */

.erp-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  z-index: 1000;
  overflow-y: auto;
  overflow-x: hidden;
}

/* Logo area */
.sidebar-logo {
  padding: 16px;
  min-height: 140px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}

.sidebar-logo img {
  max-height: 128px;
  width: auto;
  display: block;
  margin: 0 auto;
}

.sidebar-logo-text {
  font-size: 64px;
  font-weight: 600;
  color: #ffffff;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.sidebar-version {
  padding: 2px 16px 8px;
  font-size: 11px;
  color: var(--sidebar-section-label, rgba(255,255,255,0.45));
  flex-shrink: 0;
}

/* Navigation */
.sidebar-nav {
  flex: 1;
  padding: 8px 0;
}

.sidebar-section-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--sidebar-section-label);
  padding: 16px 16px 4px;
  display: block;
}

.sidebar-section-label:first-child {
  padding-top: 8px;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 13px;
  font-weight: 400;
  border-left: 3px solid transparent;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.sidebar-nav a:hover {
  background: var(--sidebar-hover-bg);
  color: #ffffff;
  text-decoration: none;
}

.sidebar-nav a.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-text);
  border-left-color: #5bb8d4;
  font-weight: 500;
}

.sidebar-nav a .nav-icon {
  font-size: 14px;
  width: 18px;
  text-align: center;
  flex-shrink: 0;
  opacity: 0.85;
}

.sidebar-nav a.active .nav-icon {
  opacity: 1;
}

/* Sub-items (indented, smaller) */
.sidebar-nav a.sub-item {
  padding-left: 44px;
  font-size: 12.5px;
}

.sidebar-divider {
  border-top: 1px solid var(--sidebar-border);
  margin: 8px 0;
}

/* Sidebar footer */
.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}

.sidebar-footer .user-name {
  font-size: 12px;
  color: var(--sidebar-text-muted);
  display: block;
  margin-bottom: 4px;
}

/* -----------------------------------------------------------------------------
   4. TOP HEADER
   ----------------------------------------------------------------------------- */

.erp-header {
  position: sticky;
  top: 0;
  height: var(--header-height);
  background: var(--header-bg);
  border-bottom: 1px solid var(--header-border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  z-index: 900;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}

.erp-header .page-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
  flex: 1;
}

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

.header-user {
  font-size: 13px;
  color: var(--text-secondary);
}

.header-user strong {
  color: var(--text-primary);
}

/* -----------------------------------------------------------------------------
   5. BREADCRUMBS
   ----------------------------------------------------------------------------- */

.erp-breadcrumb-bar {
  background: var(--card-bg);
  border-bottom: 1px solid var(--card-border);
  padding: 0 24px;
  height: 36px;
  display: flex;
  align-items: center;
}

.erp-breadcrumb {
  display: flex;
  align-items: center;
  list-style: none;
  margin: 0;
  padding: 0;
  gap: 0;
}

.erp-breadcrumb li {
  display: flex;
  align-items: center;
  font-size: 12px;
  color: var(--text-muted);
}

.erp-breadcrumb li a {
  color: var(--accent);
  text-decoration: none;
}

.erp-breadcrumb li a:hover {
  text-decoration: underline;
}

.erp-breadcrumb li + li::before {
  content: '›';
  padding: 0 6px;
  color: #cbd5e0;
}

.erp-breadcrumb li:last-child {
  color: var(--text-secondary);
  font-weight: 500;
}

/* -----------------------------------------------------------------------------
   6. CONTENT AREA
   ----------------------------------------------------------------------------- */

.erp-content {
  flex: 1;
  padding: 24px;
}

/* -----------------------------------------------------------------------------
   7. MESSAGES / ALERTS
   ----------------------------------------------------------------------------- */

.erp-messages {
  padding: 0 24px;
  padding-top: 12px;
}

.erp-alert {
  padding: 9px 14px;
  border-radius: var(--border-radius);
  font-size: 13px;
  border: 1px solid transparent;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 8px;
}

.erp-alert .close {
  margin-left: auto;
  opacity: 0.6;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  border: none;
  background: none;
  padding: 0;
}

.erp-alert-success { background: #f0fff4; border-color: #9ae6b4; color: var(--success); }
.erp-alert-error   { background: #fff5f5; border-color: #feb2b2; color: var(--danger); }
.erp-alert-warning { background: #fffbeb; border-color: #f6e05e; color: var(--warning); }
.erp-alert-info    { background: #ebf8ff; border-color: #90cdf4; color: #2b6cb0; }

/* -----------------------------------------------------------------------------
   8. CARDS
   ----------------------------------------------------------------------------- */

.erp-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-sm);
}

.erp-card-header {
  padding: 12px 16px 11px;
  border-bottom: 1px solid var(--card-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.erp-card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.erp-card-body {
  padding: 16px;
}

/* KPI cards on dashboard */
.kpi-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-sm);
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.kpi-card .kpi-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
}

.kpi-card .kpi-value {
  font-size: 26px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.1;
}

.kpi-card .kpi-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.kpi-card .kpi-icon {
  font-size: 20px;
  opacity: 0.4;
  margin-bottom: 4px;
}

.kpi-accent-blue  { border-top: 3px solid #2e7d9e; }
.kpi-accent-green { border-top: 3px solid #2f855a; }
.kpi-accent-amber { border-top: 3px solid #b7791f; }
.kpi-accent-navy  { border-top: 3px solid #1a3a5c; }

/* -----------------------------------------------------------------------------
   9. TABLES
   ----------------------------------------------------------------------------- */

.erp-table-wrapper {
  overflow-x: auto;
}

.erp-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  color: var(--text-primary);
}

.erp-table thead th {
  background: var(--table-header-bg);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 8px 12px;
  border-bottom: 2px solid var(--table-border);
  white-space: nowrap;
  cursor: default;
}

.erp-table tbody tr {
  border-bottom: 1px solid var(--table-border);
}

.erp-table tbody tr:last-child {
  border-bottom: none;
}

.erp-table tbody tr:hover {
  background: var(--table-hover);
}

.erp-table td {
  padding: 7px 12px;
  vertical-align: middle;
}

.erp-table td.td-number {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-family: 'Inter', monospace;
}

.erp-table td.td-mono {
  font-family: 'Courier New', monospace;
  font-size: 12px;
}

.erp-table-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 32px 16px;
  font-size: 13px;
}

/* Colori riga per tipo documento */
.erp-table tbody tr.row-doctype-green { background-color: #e8f5e9; }
.erp-table tbody tr.row-doctype-green:hover { background-color: #c8e6c9; }
.erp-table tbody tr.row-doctype-yellow { background-color: #fff9e6; }
.erp-table tbody tr.row-doctype-yellow:hover { background-color: #fff0b3; }
.erp-table tbody tr.row-doctype-red { background-color: #fce8e8; }
.erp-table tbody tr.row-doctype-red:hover { background-color: #f5c6c6; }

/* -----------------------------------------------------------------------------
   10. BADGES & STATUS
   ----------------------------------------------------------------------------- */

.erp-badge {
  display: inline-block;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 500;
  border-radius: 10px;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.erp-badge-blue  { background: #ebf8ff; color: #2b6cb0; }
.erp-badge-green { background: #f0fff4; color: #276749; }
.erp-badge-red   { background: #fff5f5; color: #9b2c2c; }
.erp-badge-gray  { background: #f7fafc; color: #4a5568; border: 1px solid #e2e8f0; }
.erp-badge-amber { background: #fffbeb; color: #7b341e; }

/* -----------------------------------------------------------------------------
   11. BUTTONS
   ----------------------------------------------------------------------------- */

.btn-erp-primary {
  background: var(--accent);
  color: #ffffff;
  border: 1px solid var(--accent-dark);
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--border-radius);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s;
  line-height: 1.4;
}

.btn-erp-primary:hover {
  background: var(--accent-dark);
  color: #ffffff;
  text-decoration: none;
}

.btn-erp-secondary {
  background: #ffffff;
  color: var(--text-secondary);
  border: 1px solid var(--input-border);
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--border-radius);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s;
  line-height: 1.4;
}

.btn-erp-secondary:hover {
  background: #f7fafc;
  color: var(--text-primary);
  text-decoration: none;
}

.btn-erp-danger {
  background: #c53030;
  color: #ffffff;
  border: 1px solid #9b2c2c;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--border-radius);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s;
  line-height: 1.4;
}

.btn-erp-danger:hover {
  background: #9b2c2c;
  color: #ffffff;
  text-decoration: none;
}

.btn-sm-erp {
  padding: 3px 10px;
  font-size: 12px;
}

.btn-xs {
  padding: 2px 7px;
  font-size: 11px;
  line-height: 1.4;
  border-radius: 4px;
}

/* -----------------------------------------------------------------------------
   12. FORMS
   ----------------------------------------------------------------------------- */

.erp-form-group {
  margin-bottom: 14px;
}

.erp-form-group label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.erp-form-group .form-control {
  font-size: 13px;
  padding: 6px 10px;
  border: 1px solid var(--input-border);
  border-radius: var(--border-radius);
  color: var(--text-primary);
  background: #ffffff;
  height: auto;
}

.erp-form-group .form-control:focus {
  border-color: var(--input-focus);
  box-shadow: 0 0 0 2px rgba(46,125,158,0.15);
  outline: none;
}

.erp-form-group .form-control[readonly],
.erp-form-group .form-control:disabled {
  background: #f7fafc;
  color: var(--text-muted);
}

/* -----------------------------------------------------------------------------
   13. PAGINATION
   ----------------------------------------------------------------------------- */

.erp-pagination {
  display: flex;
  justify-content: flex-end;
  gap: 4px;
  padding: 12px 16px;
  border-top: 1px solid var(--table-border);
}

.erp-pagination a,
.erp-pagination span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 28px;
  padding: 0 6px;
  border: 1px solid var(--input-border);
  border-radius: var(--border-radius);
  font-size: 12px;
  color: var(--text-secondary);
  text-decoration: none;
  background: #ffffff;
  transition: background 0.12s;
}

.erp-pagination a:hover {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent);
}

.erp-pagination .current-page {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
  font-weight: 600;
}

.erp-pagination .disabled {
  opacity: 0.4;
  pointer-events: none;
}

/* -----------------------------------------------------------------------------
   14. LOGIN PAGE
   ----------------------------------------------------------------------------- */

.login-page {
  min-height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  background: #ffffff;
  border-radius: 6px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.25);
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
}

.login-logo {
  text-align: center;
  margin-bottom: 28px;
}

.login-logo img {
  max-height: 192px;
  width: auto;
}

.login-logo .login-app-name {
  display: block;
  font-size: 72px;
  font-weight: 600;
  color: var(--sidebar-bg);
  margin-top: 10px;
  letter-spacing: 0.02em;
}

.login-card h2 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 20px;
  text-align: center;
}

.login-card .form-control {
  font-size: 13.5px;
  padding: 8px 12px;
  border: 1px solid var(--input-border);
  border-radius: var(--border-radius);
  height: auto;
  width: 100%;
  margin-bottom: 4px;
}

.login-card .form-control:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(46,125,158,0.15);
  outline: none;
}

.login-card label {
  font-size: 11.5px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  display: block;
  margin-bottom: 4px;
}

.login-submit {
  width: 100%;
  padding: 9px;
  background: var(--accent);
  color: #ffffff;
  border: none;
  border-radius: var(--border-radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
  transition: background 0.15s;
}

.login-submit:hover {
  background: var(--accent-dark);
}

.login-error {
  background: #fff5f5;
  border: 1px solid #feb2b2;
  color: var(--danger);
  font-size: 12.5px;
  border-radius: var(--border-radius);
  padding: 8px 12px;
  margin-bottom: 16px;
}

/* -----------------------------------------------------------------------------
   15. UTILITY
   ----------------------------------------------------------------------------- */

.text-number {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.text-muted-erp {
  color: var(--text-muted);
  font-size: 12px;
}

.section-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

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

/* Scrollbar styling (non-standard, best-effort) */
.erp-sidebar::-webkit-scrollbar { width: 4px; }
.erp-sidebar::-webkit-scrollbar-track { background: transparent; }
.erp-sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 4px; }

/* -----------------------------------------------------------------------------
   16. RESPONSIVE — collapse sidebar on narrow viewport
   ----------------------------------------------------------------------------- */

@media (max-width: 992px) {
  .erp-sidebar {
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }

  .erp-sidebar.sidebar-open {
    transform: translateX(0);
  }

  .erp-main {
    margin-left: 0;
  }

  .sidebar-toggle-btn {
    display: flex !important;
  }
}

.sidebar-toggle-btn {
  display: none;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid var(--header-border);
  border-radius: var(--border-radius);
  padding: 6px 8px;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 16px;
}
