/* Design Tokens & Mobile Native PWA Stylesheet */
:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  
  /* BDB Theme Defaults */
  --primary: #1e293b;
  --primary-light: #334155;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --bg-app: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text-main: #0f172a;
  --text-muted: #64748b;
  
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
}

[data-tenant="permata"] {
  --primary: #064e3b;
  --primary-light: #065f46;
  --accent: #059669;
  --accent-hover: #047857;
  --bg-app: #f0fdf4;
}

/* Reset & Native Touch Ergonomics */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  min-height: -webkit-fill-available;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  padding-bottom: calc(var(--safe-bottom) + 68px);
}

/* Header & Tenant Switcher */
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.tenant-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-unit {
  display: flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  user-select: none;
}

.brand-divider {
  width: 1px;
  height: 22px;
  background: var(--border);
}

.tenant-logo-preview {
  height: 36px;
  width: auto;
  object-fit: contain;
}

.tenant-switcher-group {
  display: flex;
  background: var(--border);
  padding: 3px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(0,0,0,0.05);
}

.btn-tenant-toggle {
  border: none;
  background: transparent;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  border-radius: calc(var(--radius-md) - 3px);
  cursor: pointer;
  touch-action: manipulation;
  transition: all 0.15s ease;
  min-height: 38px;
}

.btn-tenant-toggle.active {
  background: var(--surface);
  color: var(--text-main);
  box-shadow: var(--shadow-sm);
}

/* Main Container */
.main-content {
  flex: 1;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 16px;
}

/* Bottom Navigation Bar for Mobile */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(64px + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 60;
}

.nav-tab-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: var(--radius-md);
  min-width: 56px;
  min-height: 48px;
  touch-action: manipulation;
}

.nav-tab-item svg {
  width: 22px;
  height: 22px;
}

.nav-tab-item.active {
  color: var(--accent);
}

/* Cards & Surfaces */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}

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

.card-title {
  font-size: 17px;
  font-weight: 700;
}

/* Button & Form Controls */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  min-height: 44px;
  min-width: 44px;
  touch-action: manipulation;
  user-select: none;
  transition: all 0.15s ease;
}

.btn-primary {
  background: var(--accent);
  color: #ffffff;
}

.btn-primary:active {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text-main);
  border-color: var(--border);
}

.btn-excel {
  background: #107c41;
  color: #ffffff;
}

.btn-excel:hover {
  background: #0b5e30;
}

.btn-icon-only {
  padding: 8px 10px;
  min-width: 40px;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  border-radius: var(--radius-sm);
}

/* Document Action Group & Buttons */
.doc-action-group {
  display: flex;
  gap: 8px;
  align-items: center;
}

.doc-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 8px 16px;
  font-size: 13.5px;
  font-weight: 700;
  border-radius: var(--radius-md);
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  white-space: nowrap;
  min-height: 46px;
  text-decoration: none;
  border: none;
}

.btn-avatar-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #ffffff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.15);
  flex-shrink: 0;
  transition: transform 0.2s ease;
}

/* Button 1: Quotation (Vibrant Royal Blue) */
.btn-action-quotation {
  background: linear-gradient(135deg, #1d4ed8, #2563eb);
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.35);
}
.btn-action-quotation .avatar-quotation {
  color: #1d4ed8;
}
.btn-action-quotation:hover, .btn-action-quotation:active {
  background: linear-gradient(135deg, #1e40af, #1d4ed8);
  box-shadow: 0 6px 18px rgba(37, 99, 235, 0.45);
  transform: translateY(-1px);
}
.btn-action-quotation:hover .btn-avatar-icon {
  transform: scale(1.08);
}

/* Button 2: Surat Jalan (Vibrant Emerald Green) */
.btn-action-sj {
  background: linear-gradient(135deg, #047857, #059669);
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(5, 150, 105, 0.35);
}
.btn-action-sj .avatar-sj {
  color: #047857;
}
.btn-action-sj:hover, .btn-action-sj:active {
  background: linear-gradient(135deg, #065f46, #047857);
  box-shadow: 0 6px 18px rgba(5, 150, 105, 0.45);
  transform: translateY(-1px);
}
.btn-action-sj:hover .btn-avatar-icon {
  transform: scale(1.08);
}

/* Button 3: Purchase Request (Vibrant Amber / Gold) */
.btn-action-pr {
  background: linear-gradient(135deg, #b45309, #d97706);
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(217, 119, 6, 0.35);
}
.btn-action-pr .avatar-pr {
  color: #b45309;
}
.btn-action-pr:hover, .btn-action-pr:active {
  background: linear-gradient(135deg, #92400e, #b45309);
  box-shadow: 0 6px 18px rgba(217, 119, 6, 0.45);
  transform: translateY(-1px);
}
.btn-action-pr:hover .btn-avatar-icon {
  transform: scale(1.08);
}

/* Text-Only Filter Tabs (No Badges, Distinct Colors) */
.filter-text-tabs {
  display: flex;
  gap: 16px;
  align-items: center;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding: 4px 2px 8px 2px;
}

.text-tab-item {
  background: transparent;
  border: none;
  padding: 6px 4px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  position: relative;
  transition: all 0.15s ease;
  touch-action: manipulation;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.text-tab-item.tab-all {
  color: #64748b;
}
.text-tab-item.tab-all.active,
.text-tab-item.tab-all:hover {
  color: #0f172a;
}
.text-tab-item.tab-all.active::after {
  content: '';
  position: absolute;
  bottom: -6px;
  left: 0;
  right: 0;
  height: 3px;
  background: #0f172a;
  border-radius: 2px;
}

.text-tab-item.tab-quotation {
  color: #3b82f6;
}
.text-tab-item.tab-quotation.active,
.text-tab-item.tab-quotation:hover {
  color: #1d4ed8;
}
.text-tab-item.tab-quotation.active::after {
  content: '';
  position: absolute;
  bottom: -6px;
  left: 0;
  right: 0;
  height: 3px;
  background: #1d4ed8;
  border-radius: 2px;
}

.text-tab-item.tab-sj {
  color: #10b981;
}
.text-tab-item.tab-sj.active,
.text-tab-item.tab-sj:hover {
  color: #047857;
}
.text-tab-item.tab-sj.active::after {
  content: '';
  position: absolute;
  bottom: -6px;
  left: 0;
  right: 0;
  height: 3px;
  background: #047857;
  border-radius: 2px;
}

.text-tab-item.tab-pr {
  color: #f59e0b;
}
.text-tab-item.tab-pr.active,
.text-tab-item.tab-pr:hover {
  color: #b45309;
}
.text-tab-item.tab-pr.active::after {
  content: '';
  position: absolute;
  bottom: -6px;
  left: 0;
  right: 0;
  height: 3px;
  background: #b45309;
  border-radius: 2px;
}

/* Responsive Form Field Layouts */
.form-section-title {
  font-size: 13.5px;
  font-weight: 800;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.form-grid-responsive-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 16px;
}

.form-grid-responsive-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  margin-bottom: 16px;
}

.form-grid-responsive-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
}

.form-label {
  display: block;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 6px;
}

.form-label-sub {
  font-size: 11px;
  font-weight: normal;
  color: var(--text-muted);
  margin-left: 4px;
}

.calc-summary-wrapper {
  display: flex;
  justify-content: flex-end;
  margin-top: 14px;
}

.calc-summary-card {
  width: 340px;
  background: #f8fafc;
  padding: 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-size: 13.5px;
}

/* Table Column Controls */
.col-no { width: 44px; min-width: 44px; text-align: center; }
.col-desc { min-width: 200px; }
.col-spec { min-width: 140px; }
.col-qty { width: 80px; min-width: 80px; }
.col-qty-send { width: 90px; min-width: 90px; }
.col-unit { width: 85px; min-width: 85px; }
.col-price { width: 130px; min-width: 130px; }
.col-total { width: 130px; min-width: 130px; }
.col-action { width: 50px; min-width: 50px; text-align: center; }

.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 12px;
  font-size: 16px; /* Prevents iOS auto-zoom */
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-main);
  outline: none;
  margin-bottom: 0;
}

.form-group .form-input,
.form-group .form-select,
.form-group .form-textarea {
  margin-bottom: 0;
}

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

/* Responsive Table */
.table-responsive-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.styled-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

.styled-table th {
  background: #f1f5f9;
  text-align: left;
  padding: 10px 12px;
  font-weight: 700;
  border-bottom: 1px solid var(--border);
}

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

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-dialog {
  background: var(--surface);
  width: 100%;
  max-width: 600px;
  max-height: 85vh;
  border-top-left-radius: var(--radius-lg);
  border-top-right-radius: var(--radius-lg);
  padding: 20px;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  transform: translateY(100%);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@media (min-width: 768px) {
  .modal-overlay {
    align-items: center;
    padding: 20px;
  }
  .modal-dialog {
    border-radius: var(--radius-lg);
    transform: scale(0.95);
  }
}

.modal-overlay.open .modal-dialog {
  transform: translateY(0) scale(1);
}

/* Live Document Print Preview (A4 Calibrated) */
.doc-a4-preview, .a4-sheet-container {
  background: #ffffff;
  color: #000000;
  width: 100%;
  max-width: 210mm;
  min-height: 297mm;
  margin: 0 auto 24px;
  padding: 16mm 14mm;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
  font-size: 12px;
  line-height: 1.4;
  position: relative;
  box-sizing: border-box;
}

/* Document Cards & Badges */
.doc-list-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 14px;
}

.doc-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.doc-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.doc-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.badge {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.badge-ph { background: #dbeafe; color: #1d4ed8; }
.badge-sj { background: #d1fae5; color: #047857; }
.badge-pr { background: #fef3c7; color: #b45309; }

.status-draft { background: #f1f5f9; color: #475569; }
.status-sent { background: #e0e7ff; color: #4338ca; }
.status-approved { background: #dcfce7; color: #15803d; }
.status-rejected { background: #fee2e2; color: #b91c1c; }

.tab-chip {
  padding: 7px 16px;
  border-radius: 24px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
  touch-action: manipulation;
}

.tab-chip.active {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
  box-shadow: var(--shadow-sm);
}

.btn-sm {
  padding: 6px 10px;
  font-size: 12px;
  min-height: 32px;
  min-width: 32px;
  border-radius: 6px;
}

.empty-state {
  text-align: center;
  padding: 48px 16px;
  background: var(--surface);
  border-radius: var(--radius-md);
  border: 1px dashed var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.7);
  backdrop-filter: blur(5px);
  z-index: 1000;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 16px;
}

.modal-content {
  background: var(--surface);
  border-radius: var(--radius-lg);
  max-width: 900px;
  width: 100%;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.3);
}

@media (max-width: 768px) {
  .modal-fullscreen-mobile {
    max-width: 100% !important;
    width: 100% !important;
    height: 100% !important;
    max-height: 100vh !important;
    border-radius: 0 !important;
    margin: 0 !important;
  }
}

.modal-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  z-index: 10;
}

.text-danger { color: #dc2626 !important; }
.text-success { color: #16a34a !important; }

/* Dashboard Summary Cards */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
}

.stat-val {
  font-size: 26px;
  font-weight: 800;
  color: var(--accent);
  margin-top: 4px;
}

.stat-label {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 600;
}

@media (max-width: 1080px) {
  .doc-header-section {
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
  }
  .doc-action-group {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    width: 100%;
    gap: 8px;
  }
  .doc-action-btn {
    width: 100%;
    padding: 10px 6px;
    font-size: 12.5px;
    text-align: center;
  }
  .form-grid-responsive-4 {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 640px) {
  .tenant-brand {
    gap: 8px;
  }
  .brand-unit {
    gap: 4px;
  }
  .tenant-logo-preview {
    height: 30px;
  }
  .brand-divider {
    height: 18px;
  }
  .doc-action-group {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  .doc-action-btn {
    font-size: 13.5px;
    padding: 11px 14px;
    justify-content: center;
  }
  .form-grid-responsive-4,
  .form-grid-responsive-2,
  .form-grid-responsive-3 {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .calc-summary-wrapper {
    justify-content: stretch;
  }
  .calc-summary-card {
    width: 100%;
  }
}

/* Print CSS Calibrations */
@media print {
  @page {
    size: A4 portrait;
    margin: 10mm;
  }
  body {
    background: #ffffff !important;
    padding: 0 !important;
  }
  .app-header, .bottom-nav, .no-print, .modal-header, .modal-backdrop {
    display: none !important;
  }
  .modal-backdrop {
    position: static !important;
    background: transparent !important;
    padding: 0 !important;
  }
  .modal-content {
    box-shadow: none !important;
    border: none !important;
    max-height: none !important;
    overflow: visible !important;
  }
  .modal-preview-content, .preview-scroll-body {
    background: transparent !important;
    padding: 0 !important;
    overflow: visible !important;
  }
  .doc-a4-preview, .a4-sheet-container {
    border: none !important;
    box-shadow: none !important;
    margin: 0 !important;
    padding: 0 !important;
    max-width: 100% !important;
    min-height: auto !important;
    width: 100% !important;
  }
}

