/* Fonts & Colors System */
:root {
  --bg: #f8fafc;
  --panel: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --blue: #2563eb;
  --green: #16a34a;
  --amber: #ea580c;
  --red: #dc2626;
  --cyan: #0891b2;
  --shadow: 0 10px 30px -10px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 20px 40px -15px rgba(15, 23, 42, 0.12);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --font-title: 'Outfit', sans-serif;
  --font-body: 'Plus Jakarta Sans', sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  letter-spacing: -0.01em;
  min-height: 100vh;
}

body.logged-out .app-shell {
  display: none;
}

button,
input,
textarea,
select {
  font: inherit;
  letter-spacing: inherit;
}

button {
  border: 0;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Scrollbar Customization */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* Shell Layout */
.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  background: var(--bg);
}

/* Sidebar Styling */
.sidebar {
  background: #0f172a;
  color: #fff;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  border-right: 1px solid rgba(255, 255, 255, 0.05);
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 90;
}

.close-sidebar {
  display: none;
  position: absolute;
  top: 20px;
  right: 20px;
  background: transparent;
  color: #fff;
  font-size: 28px;
  border: 0;
  padding: 0;
  width: 32px;
  height: 32px;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  cursor: pointer;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 8px 8px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  color: #0f172a;
  font-family: var(--font-title);
  font-weight: 800;
  font-size: 20px;
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.2);
}

.brand strong {
  font-family: var(--font-title);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #fff;
}

.brand span {
  display: block;
  margin-top: 2px;
  color: #94a3b8;
  font-size: 12px;
}

.brand-logo {
  max-height: 48px;
  max-width: 100%;
  object-fit: contain;
  filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.2));
}

.nav {
  display: grid;
  gap: 6px;
  overflow-y: auto;
  flex: 1;
  padding-right: 4px;
}

.nav button {
  min-height: 44px;
  border-radius: 10px;
  background: transparent;
  color: #94a3b8;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  text-align: left;
  font-weight: 500;
  font-size: 14px;
}

.nav button:hover,
.nav button.active {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
}

.nav button.active {
  background: var(--blue);
  color: #fff;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
}

.nav-icon-svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  transition: transform 0.2s ease;
}

.nav button:hover .nav-icon-svg {
  transform: scale(1.05);
}

/* User Profile Panel in Sidebar */
.user-profile-strip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 12px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 12px;
  margin-top: auto;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 14px;
}

.user-info {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

.user-name {
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  color: #64748b;
  font-size: 11px;
  font-weight: 500;
}

.btn-logout {
  background: transparent;
  color: #94a3b8;
  padding: 6px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-logout:hover {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
}

/* Main Area */
.main {
  min-width: 0;
  padding: 32px;
  overflow-y: auto;
  height: 100vh;
}

/* Topbar Header */
.topbar {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: center;
  margin-bottom: 32px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.menu-toggle {
  display: none;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  padding: 10px;
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.menu-toggle:hover {
  background: #f1f5f9;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  font-weight: 800;
  letter-spacing: 0.05em;
}

h1, h2, h3, p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-family: var(--font-title);
  font-size: 32px;
  font-weight: 800;
  color: var(--ink);
}

h2 {
  font-family: var(--font-title);
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--ink);
}

h3 {
  font-family: var(--font-title);
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
}

.status-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.status-strip span,
.badge {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  border-radius: 30px;
  background: #e2e8f0;
  color: #334155;
  padding: 6px 14px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.badge.green, .status-strip span#db-status.green, .status-strip span#cash-status.green, .status-strip span#whatsapp-status.green {
  background: #dcfce7;
  color: #15803d;
}

.badge.amber, .status-strip span#db-status.amber, .status-strip span#cash-status.amber, .status-strip span#whatsapp-status.amber {
  background: #ffedd5;
  color: #c2410c;
}

.badge.red {
  background: #fee2e2;
  color: #b91c1c;
}

/* Views and Panels */
.view {
  display: grid;
  gap: 24px;
  animation: fadeIn 0.3s ease;
}

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

.grid {
  display: grid;
  gap: 24px;
}

.grid.cols-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid.cols-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.grid.cols-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  padding: 24px;
  min-width: 0;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.panel:hover {
  box-shadow: var(--shadow-lg);
}

.metric {
  min-height: 120px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, #ffffff, #f8fafc);
}

.metric::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: var(--blue);
}

.metric:nth-child(2)::after { background: var(--green); }
.metric:nth-child(3)::after { background: var(--amber); }
.metric:nth-child(4)::after { background: var(--cyan); }

.metric span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.metric strong {
  font-family: var(--font-title);
  font-size: 28px;
  font-weight: 800;
  color: var(--ink);
}

/* Forms styling */
.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.form-grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

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

label {
  display: grid;
  gap: 6px;
  color: #334155;
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid #cbd5e1;
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--ink);
  padding: 10px 14px;
  outline: none;
  font-family: inherit;
  font-size: 14px;
  transition: all 0.2s ease;
}

textarea {
  min-height: 96px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1);
}

/* Buttons */
.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.btn {
  min-height: 42px;
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  background: #f1f5f9;
  color: #334155;
  font-weight: 700;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}

.btn:hover {
  background: #e2e8f0;
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn.primary {
  background: var(--blue);
  color: #fff;
}
.btn.primary:hover {
  background: #1d4ed8;
  box-shadow: 0 4px 12px rgba(29, 78, 216, 0.25);
}

.btn.green {
  background: var(--green);
  color: #fff;
}
.btn.green:hover {
  background: #15803d;
  box-shadow: 0 4px 12px rgba(21, 128, 61, 0.25);
}

.btn.amber {
  background: var(--amber);
  color: #fff;
}
.btn.amber:hover {
  background: #ea580c;
  box-shadow: 0 4px 12px rgba(234, 88, 12, 0.25);
}

.btn.red {
  background: var(--red);
  color: #fff;
}
.btn.red:hover {
  background: #b91c1c;
  box-shadow: 0 4px 12px rgba(185, 28, 28, 0.25);
}

.btn.ghost {
  background: transparent;
  color: var(--blue);
  box-shadow: none;
}
.btn.ghost:hover {
  background: rgba(37, 99, 235, 0.08);
}

/* Tables */
.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 800px;
}

th, td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  font-size: 14px;
}

th {
  background: #f8fafc;
  color: #475569;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

tr:last-child td {
  border-bottom: 0;
}

tr:hover td {
  background: #f8fafc;
}

.total-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-top: 2px solid var(--line);
  padding: 16px 4px 0;
  margin-top: 16px;
  font-family: var(--font-title);
  font-weight: 800;
  font-size: 18px;
}

/* Shopping Cart */
.cart-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.cart-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 12px;
  align-items: center;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #f8fafc;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.02);
}

/* Toast Messages */
.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 1000;
  max-width: 400px;
  border-radius: var(--radius-md);
  padding: 14px 20px;
  background: #0f172a;
  color: #fff;
  box-shadow: var(--shadow-lg);
  font-weight: 700;
  font-size: 14px;
  animation: slideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes slideUp {
  from { transform: translateY(100%) scale(0.9); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}

.empty {
  min-height: 120px;
  border: 2px dashed #cbd5e1;
  border-radius: var(--radius-md);
  display: grid;
  place-items: center;
  color: var(--muted);
  text-align: center;
  padding: 24px;
  font-weight: 500;
}

.split-title {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 20px;
}

.split-title h2 {
  margin-bottom: 0;
}

/* Modern Login Page (Premium Design) */
.login-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 10% 20%, rgba(90, 187, 240, 0.2) 0%, rgba(200, 250, 240, 0.1) 90.1%), linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  padding: 24px;
  font-family: var(--font-body);
}

.login-card {
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(12px);
  border-radius: var(--radius-lg);
  box-shadow: 0 30px 60px -15px rgba(0, 0, 0, 0.3);
  width: 100%;
  max-width: 440px;
  padding: 40px;
  text-align: center;
  animation: loginAppear 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.login-logo {
  width: 80px;
  height: 80px;
  margin: 0 auto 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: white;
  border-radius: 20px;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
  padding: 10px;
}

.login-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.login-card h2 {
  margin-bottom: 4px;
  font-size: 26px;
  font-family: var(--font-title);
  font-weight: 900;
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.login-subtitle {
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 28px;
}

.login-form {
  display: grid;
  gap: 18px;
  text-align: left;
}

.login-form label {
  font-weight: 600;
}

.login-form input {
  background: #f1f5f9;
  border-color: #e2e8f0;
}

.login-form input:focus {
  background: #fff;
}

.login-form .btn {
  margin-top: 10px;
  width: 100%;
  font-size: 15px;
}

/* Documentation Styling & Markdown Body */
.doc-section {
  display: flex;
  flex-direction: column;
  gap: 24px;
  margin-bottom: 30px;
}

.doc-header {
  padding: 24px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  background: var(--panel);
}

.doc-filters {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.btn-doc-filter {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  font-family: var(--font-title);
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-doc-filter:hover {
  background: var(--line);
}

.btn-doc-filter.active {
  background: var(--blue);
  color: #ffffff;
  border-color: var(--blue);
}

.doc-rendered {
  background: var(--panel);
  border-radius: var(--radius-md);
  padding: 32px;
  box-shadow: var(--shadow);
  line-height: 1.7;
  color: var(--ink);
}

/* Document visibility toggles */
.doc-rendered.show-all .doc-leigo,
.doc-rendered.show-all .doc-tecnico {
  display: block;
}

.doc-rendered.show-leigo .doc-leigo {
  display: block;
}
.doc-rendered.show-leigo .doc-tecnico {
  display: none;
}

.doc-rendered.show-tecnico .doc-tecnico {
  display: block;
}
.doc-rendered.show-tecnico .doc-leigo {
  display: none;
}

/* Markdown specific tags styles within rendered view */
.doc-rendered h1,
.doc-rendered h2,
.doc-rendered h3,
.doc-rendered h4 {
  color: var(--ink);
  font-family: var(--font-title);
  margin-top: 1.8em;
  margin-bottom: 0.6em;
  font-weight: 700;
}

.doc-rendered h1:first-child,
.doc-rendered h2:first-child {
  margin-top: 0;
}

.doc-rendered h1 {
  font-size: 28px;
  border-bottom: 2px solid var(--line);
  padding-bottom: 8px;
}

.doc-rendered h2 {
  font-size: 22px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 6px;
}

.doc-rendered h3 {
  font-size: 18px;
}

.doc-rendered p {
  margin-bottom: 16px;
  font-size: 15px;
  color: var(--ink);
}

.doc-rendered ul,
.doc-rendered ol {
  margin-bottom: 20px;
  padding-left: 24px;
}

.doc-rendered li {
  margin-bottom: 8px;
  font-size: 15px;
}

.doc-rendered hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 32px 0;
}

/* Code styling */
.doc-rendered code {
  font-family: monospace;
  background: var(--bg);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--blue);
  font-weight: 600;
}

.doc-rendered pre {
  background: #1e293b;
  border-radius: var(--radius-sm);
  padding: 16px;
  overflow-x: auto;
  margin-bottom: 20px;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.3);
}

.doc-rendered pre code {
  background: transparent;
  padding: 0;
  color: #f8fafc;
  font-size: 13.5px;
  font-weight: 400;
  font-family: monospace;
}

/* Table styling */
.doc-rendered table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 24px;
  margin-top: 12px;
  font-size: 14.5px;
}

.doc-rendered th,
.doc-rendered td {
  border: 1px solid var(--line);
  padding: 12px 14px;
  text-align: left;
}

.doc-rendered th {
  background: var(--bg);
  font-weight: 700;
  color: var(--ink);
}

.doc-rendered tr:nth-child(even) {
  background: rgba(0, 0, 0, 0.02);
}

/* Image styles within documentation */
.doc-rendered img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
  margin: 16px 0;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

/* Responsiveness Settings */
@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: -280px;
    height: 100vh;
    width: 280px;
    transition: left 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 10px 0 30px rgba(0, 0, 0, 0.2);
  }

  .sidebar.open {
    left: 0;
  }

  .close-sidebar {
    display: flex;
  }

  .menu-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    padding: 0;
  }

  .nav {
    overflow-y: auto;
  }

  .grid.cols-2,
  .grid.cols-3,
  .grid.cols-4,
  .form-grid,
  .form-grid.two {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: center;
    flex-direction: row;
    gap: 12px;
  }
  
  .status-strip {
    display: none; /* Hide on mobile to save space */
  }

  .main {
    padding: 16px;
  }
}

@media (max-width: 480px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }
  .topbar-left {
    width: 100%;
    justify-content: space-between;
  }
  .login-card {
    padding: 24px;
  }
}

/* Master Panel Specific Styles */
.master-tabs {
  display: flex;
  gap: 16px;
  border-bottom: 2px solid var(--line);
  padding-bottom: 0;
  margin-bottom: 24px;
  overflow-x: auto;
}
.master-tab-btn {
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  padding: 12px 18px;
  border-bottom: 3px solid transparent;
  transition: all 0.2s ease;
  font-size: 14px;
}
.master-tab-btn:hover {
  color: var(--ink);
  background: rgba(0, 0, 0, 0.02);
}
.master-tab-btn.active {
  color: var(--blue);
  border-bottom-color: var(--blue);
}
.limit-badge {
  font-size: 12px;
  font-weight: 700;
  color: #475569;
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
}
.limit-bar {
  height: 8px;
  background: var(--line);
  border-radius: 4px;
  overflow: hidden;
  margin-top: 4px;
}
.limit-fill {
  height: 100%;
  background: var(--blue);
  border-radius: 4px;
  transition: width 0.3s ease;
}
.limit-fill.warning {
  background: var(--amber);
}
.limit-fill.danger {
  background: var(--red);
}
.company-saas-card {
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.company-saas-card:hover {
  border-color: #cbd5e1;
}
.edit-limits-panel {
  animation: slideDown 0.2s ease;
}
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

