/* ══════════════════════════════════════════════════════════
   ROHU Contable — Design System CSS
   Colors, layout, components, responsive, offline indicator
   ══════════════════════════════════════════════════════════ */

:root {
  --primary: #1E3A8A;
  --primary-light: #3B5CB8;
  --primary-dark: #162D6B;
  --secondary: #10B981;
  --secondary-dark: #065F46;
  --accent: #06B6D4;
  --bg: #F8FAFC;
  --bg-card: #FFFFFF;
  --text: #0F172A;
  --text-light: #64748B;
  --border: #E2E8F0;
  --warning: #F59E0B;
  --danger: #EF4444;
  --success: #22C55E;
  --info: #3B82F6;
  --sidebar-w: 240px;
  --header-h: 56px;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.15);

  /* Typography scale */
  --fs-xs: 0.75rem;     /* 12px — badges, metadata */
  --fs-sm: 0.8125rem;   /* 13px — labels, secondary */
  --fs-base: 0.875rem;  /* 14px — body default */
  --fs-md: 1rem;        /* 16px — inputs, emphasis */
  --fs-lg: 1.125rem;    /* 18px — subtitles */
  --fs-xl: 1.5rem;      /* 24px — page titles */
  --fs-2xl: 1.75rem;    /* 28px — KPI values */
  --fs-3xl: 2.25rem;    /* 36px — POS total */
}

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

html { font-size: 16px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: var(--fs-base);
  line-height: 1.5;
}

/* ── Layout ─────────────────────────────────────────────── */

.app-layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  background: var(--primary);
  color: white;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 1000;
  transition: transform 0.3s ease;
}

/* Overlay behind sidebar on mobile */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 999;
}
.sidebar-overlay.active { display: block; }

.sidebar-brand {
  padding: 16px 20px;
  font-size: 20px;
  font-weight: 700;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-brand span { color: var(--secondary); }

.sidebar-nav { flex: 1; padding: 12px 0; overflow-y: auto; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  color: rgba(255,255,255,0.7);
  text-decoration: none;
  font-size: 14px;
  transition: all 0.2s;
  border-left: 3px solid transparent;
}

.nav-item:hover, .nav-item.active {
  background: rgba(255,255,255,0.1);
  color: white;
  border-left-color: var(--secondary);
}

.nav-item svg { width: 20px; height: 20px; flex-shrink: 0; }

.nav-section {
  padding: 8px 20px 4px;
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 1px;
  color: rgba(255,255,255,0.65);
  margin-top: 8px;
}

.main-content {
  flex: 1;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
}

/* ── Header ─────────────────────────────────────────────── */

.header {
  height: var(--header-h);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.header-title { font-size: 18px; font-weight: 600; }

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

.online-badge, .offline-badge {
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

.online-badge { background: #DCFCE7; color: var(--secondary-dark); }
.offline-badge { background: #FEF3C7; color: #92400E; }

.menu-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 8px;
}

/* ── Page Content ───────────────────────────────────────── */

.page { padding: 24px; flex: 1; }

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.page-title { font-size: var(--fs-xl); font-weight: 700; }

/* ── Cards ──────────────────────────────────────────────── */

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

.card-title {
  font-size: var(--fs-sm);
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.card-value {
  font-size: var(--fs-2xl);
  font-weight: 700;
  color: var(--text);
}

.card-value.positive { color: var(--success); }
.card-value.negative { color: var(--danger); }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

/* ── Buttons ────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  min-height: 40px;
  border: none;
  border-radius: var(--radius);
  font-size: var(--fs-base);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-light); }

.btn-success { background: var(--secondary); color: white; }
.btn-success:hover { background: var(--secondary-dark); }

.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #DC2626; }

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-lg { padding: 14px 28px; font-size: 18px; font-weight: 700; }

.btn-checkout {
  background: var(--secondary);
  color: white;
  font-size: 20px;
  font-weight: 700;
  padding: 18px 32px;
  width: 100%;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 60px;
  position: relative;
}

.btn-checkout:hover:not(:disabled) { background: var(--secondary-dark); transform: translateY(-1px); }
.btn-checkout:active:not(:disabled) { transform: translateY(0); }
.btn-checkout:disabled { background: #94A3B8; cursor: not-allowed; }

.btn-checkout .shortcut-badge {
  background: rgba(255,255,255,0.2);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.5px;
}

.btn-sm { padding: 6px 12px; font-size: var(--fs-xs); }

/* ── Tabs ──────────────────────────────────────────────── */

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 2px solid var(--border);
  padding-bottom: 0;
}

.tab {
  padding: 10px 20px;
  border: none;
  background: none;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text-light);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.2s;
  border-radius: var(--radius) var(--radius) 0 0;
}

.tab:hover { color: var(--primary); background: var(--bg); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); background: var(--bg); }

/* ── Badges ────────────────────────────────────────────── */

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.3px;
}
.badge-success { background: #DCFCE7; color: #166534; }
.badge-warning { background: #FEF3C7; color: #92400E; }
.badge-danger { background: #FEE2E2; color: #991B1B; }
.badge-info { background: #DBEAFE; color: #1E40AF; }
.badge-muted { background: #F1F5F9; color: #64748B; }

/* ── Tables ─────────────────────────────────────────────── */

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th {
  text-align: left;
  padding: 10px 12px;
  background: var(--bg);
  color: var(--text-light);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 2px solid var(--border);
}

td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

tr:hover { background: #F1F5F9; }

/* ── Forms & Inputs ─────────────────────────────────────── */

.form-group { margin-bottom: 16px; }

.form-group label {
  display: block;
  margin-bottom: 4px;
  font-weight: 500;
  font-size: 13px;
  color: var(--text-light);
}

.form-control {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: var(--fs-md); /* 16px — prevents iOS zoom on focus */
  transition: border-color 0.2s;
  background: white;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(30,58,138,0.1);
}

.search-input {
  padding: 10px 12px 10px 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2394A3B8'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 12px center;
  background-size: 18px;
}

/* ── POS Layout ─────────────────────────────────────────── */

.pos-layout {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 16px;
  height: calc(100vh - var(--header-h) - 120px);
  min-height: 400px;
}

.pos-products { overflow-y: auto; }

.pos-cart {
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-height: 100%;
  overflow: visible;
}

.cart-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  font-size: 16px;
}

.cart-items { flex: 1; overflow-y: auto; padding: 8px 0; }

.cart-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}

.cart-item-info { flex: 1; }
.cart-item-name { font-weight: 500; font-size: 14px; }
.cart-item-price { font-size: 13px; color: var(--text-light); }

.cart-item-qty {
  display: flex;
  align-items: center;
  gap: 4px;
}

.cart-item-qty button {
  width: 40px; height: 40px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: white;
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cart-item-qty input {
  width: 40px;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px;
  font-size: 14px;
}

.cart-item-total { font-weight: 700; min-width: 80px; text-align: right; }

.cart-footer {
  border-top: 2px solid var(--primary);
  padding: 16px;
  flex-shrink: 0;
  background: var(--bg-card);
}

.cart-totals { margin-bottom: 12px; }

.cart-total-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 14px;
}

.cart-total-row.total {
  font-size: 22px;
  font-weight: 700;
  color: var(--primary);
  padding: 8px 0;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}

/* ── Chart Compact + Expand ─────────────────────────────── */

.chart-wrap {
  position: relative;
  height: 130px;
}

.chart-expand-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(255,255,255,0.8);
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 36px;
  height: 36px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: var(--text-light);
  transition: all 0.2s;
  z-index: 10;
}

.tab-btn.active {
  background: var(--primary) !important;
  color: white !important;
  border-color: var(--primary) !important;
}

.chart-expand-btn:hover {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* ── Product Grid (POS) ─────────────────────────────────── */

.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}

.product-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
}

.product-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

.product-card-name { font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.product-card-price { color: var(--primary); font-weight: 700; font-size: 16px; }
.product-card-stock { font-size: 12px; color: var(--text-light); }
.product-card-stock.low { color: var(--danger); font-weight: 600; }

/* ── Alerts / Badges ────────────────────────────────────── */

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
}

.badge-success { background: #DCFCE7; color: var(--secondary-dark); }
.badge-warning { background: #FEF3C7; color: #92400E; }
.badge-danger { background: #FEE2E2; color: #991B1B; }
.badge-info { background: #DBEAFE; color: #1E40AF; }

.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 14px;
}

.alert-warning { background: #FEF3C7; border-left: 4px solid var(--warning); }
.alert-danger { background: #FEE2E2; border-left: 4px solid var(--danger); }
.alert-success { background: #DCFCE7; border-left: 4px solid var(--success); }

/* ── Login Page ─────────────────────────────────────────── */

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
}

.login-card {
  background: white;
  border-radius: 12px;
  padding: 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
}

.login-brand {
  text-align: center;
  margin-bottom: 32px;
}

.login-brand h1 {
  font-size: 28px;
  color: var(--primary);
}

.login-brand h1 span { color: var(--secondary); }

.login-brand p {
  color: var(--text-light);
  font-size: 14px;
  margin-top: 4px;
}

/* ── Responsive Grid Utilities ──────────────────────────── */

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.grid-2-1 { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; margin-bottom: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; margin-bottom: 16px; }

/* ── Responsive ─────────────────────────────────────────── */

@media (max-width: 1024px) {
  .pos-layout {
    grid-template-columns: 1fr;
    height: auto;
  }
  .pos-cart { max-height: 60vh; overflow: visible; }
  .cart-footer {
    position: sticky; bottom: 0; z-index: 10;
    background: var(--bg-card);
    box-shadow: 0 -4px 12px rgba(0,0,0,0.1);
  }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }

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

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

  .menu-toggle {
    display: block;
  }

  .page { padding: 16px; }

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

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

  .pos-layout {
    grid-template-columns: 1fr;
  }

  /* POS mobile optimizations */
  .cart-footer {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
    background: var(--bg-card); border-top: 2px solid var(--primary);
    box-shadow: 0 -4px 12px rgba(0,0,0,0.15);
    padding: 12px 16px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
  .pos-cart { max-height: none; overflow: visible; padding-bottom: 180px; }
  .cart-item-qty button { width: 44px; height: 44px; font-size: 20px; }
  .cart-item-qty input { width: 48px; font-size: 16px; }
  .cart-item-total { display: none; }
  .btn-checkout { min-height: 56px; font-size: 18px; }

  .header-title { font-size: var(--fs-md); }

  .grid-2, .grid-2-1, .grid-3 {
    grid-template-columns: 1fr;
  }

  /* Buttons touch-friendly */
  .btn { min-height: 44px; }

  /* Modales responsive — override inline max-width */
  div[style*="position:fixed"] > div[style*="max-width"],
  div[style*="position: fixed"] > div[style*="max-width"] {
    max-width: 95vw !important;
    margin: 0 auto !important;
    max-height: 90vh;
    overflow-y: auto;
  }
}

/* ── Help Drawer ────────────────────────────────────────── */

.help-btn {
  display: flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 50%;
  border: 1px solid var(--border); background: white;
  cursor: pointer; font-size: 16px; font-weight: 700;
  color: var(--text-light); transition: all 0.2s;
}
.help-btn:hover { background: var(--primary); color: white; border-color: var(--primary); }

.help-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.3); z-index: 1100;
}
.help-overlay.active { display: block; }

.help-drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: 380px; max-width: 95vw;
  background: white; z-index: 1101;
  box-shadow: -4px 0 20px rgba(0,0,0,0.15);
  transform: translateX(100%);
  transition: transform 0.3s ease;
  display: flex; flex-direction: column;
}
.help-drawer.open { transform: translateX(0); }

.help-drawer-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.help-drawer-tabs {
  display: flex; border-bottom: 1px solid var(--border);
}
.help-tab {
  flex: 1; padding: 10px; border: none; background: none;
  cursor: pointer; font-size: 13px; font-weight: 600;
  color: var(--text-light); border-bottom: 2px solid transparent;
}
.help-tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.help-drawer-body { flex: 1; overflow-y: auto; padding: 16px 20px; }
.help-drawer-footer {
  padding: 12px 20px; border-top: 1px solid var(--border); text-align: center;
}

@media (max-width: 600px) {
  .help-drawer {
    top: auto; left: 0; right: 0; bottom: 0;
    width: 100%; height: 65vh; max-width: 100%;
    transform: translateY(100%); border-radius: 16px 16px 0 0;
  }
  .help-drawer.open { transform: translateY(0); }
}

/* ── ROHU Avatar (CSS animated assistant) ────────────── */
.rohu-avatar {
  display: inline-block; position: relative; width: 64px; height: 64px;
}
.rohu-avatar .head {
  width: 52px; height: 52px; background: #1E3A8A; border-radius: 50%;
  position: absolute; top: 0; left: 6px;
  display: flex; align-items: center; justify-content: center;
}
.rohu-avatar .eyes {
  display: flex; gap: 10px; margin-top: -4px;
}
.rohu-avatar .eye {
  width: 8px; height: 10px; background: white; border-radius: 50%;
  animation: rohu-blink 3.5s infinite;
}
.rohu-avatar .mouth {
  width: 14px; height: 7px; border-bottom: 3px solid white;
  border-radius: 0 0 10px 10px; margin-top: 2px;
}
.rohu-avatar .hand {
  position: absolute; bottom: 2px; right: -2px; font-size: 20px;
  animation: rohu-wave 2s ease-in-out infinite;
  transform-origin: 70% 70%;
}
@keyframes rohu-blink {
  0%, 90%, 100% { transform: scaleY(1); }
  95% { transform: scaleY(0.1); }
}
@keyframes rohu-wave {
  0%, 100% { transform: rotate(0deg); }
  15% { transform: rotate(14deg); }
  30% { transform: rotate(-8deg); }
  45% { transform: rotate(14deg); }
  60% { transform: rotate(-4deg); }
  75% { transform: rotate(10deg); }
}
.rohu-avatar-sm { transform: scale(0.7); display: inline-block; vertical-align: middle; margin: -8px 4px -8px 0; }

/* Guide card with avatar */
.guide-card {
  background: linear-gradient(135deg, #EFF6FF 0%, #F0F9FF 100%);
  border: 1px solid #BFDBFE; border-radius: 12px;
  padding: 16px 20px; display: flex; gap: 16px; align-items: flex-start;
}
.guide-card .guide-text { flex: 1; font-size: 13px; color: #1E40AF; line-height: 1.7; }
.guide-card .guide-text strong { color: #1E3A8A; }
.guide-card ol { margin: 8px 0 0 16px; padding: 0; }

@media (max-width: 600px) {
  .page-title { font-size: var(--fs-lg); }
  .card-value { font-size: var(--fs-xl); }
  .btn-checkout { font-size: var(--fs-lg); padding: 14px 20px; }
  .page-header { flex-direction: column; align-items: flex-start; gap: 12px; }
}

@media (max-width: 480px) {
  html { font-size: 14px; }
  .page { padding: 10px; }
  .kpi-grid { grid-template-columns: 1fr; }
  .product-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .card { padding: 14px; }
  .card-value { font-size: 1.25rem; }
  .login-card { padding: 24px 16px; }

  /* Modales full-width en móvil pequeño */
  div[style*="position:fixed"] > div[style*="max-width"],
  div[style*="position: fixed"] > div[style*="max-width"] {
    max-width: 100% !important;
    border-radius: 16px 16px 0 0 !important;
    padding: 16px !important;
  }

  /* Grids dentro de modales colapsan */
  div[style*="position:fixed"] div[style*="grid-template-columns"],
  div[style*="position: fixed"] div[style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
  }

  /* Tablas compactas */
  th, td { padding: 6px 8px; font-size: 12px; }
  .cart-total-row.total { font-size: 18px; }
}
