/* Digitization Project - Main Stylesheet */
:root {
  --sf-primary: #4f46e5;
  --sf-secondary: #7c3aed;
  --sf-accent: #06b6d4;
  --sf-sidebar-width: 260px;
  --sf-sidebar-collapsed: 70px;
  --sf-topbar-height: 60px;
  --sf-bg: #f8f9fa;
  --sf-card-bg: #ffffff;
  --sf-text: #1e293b;
  --sf-text-muted: #64748b;
  --sf-border: #e2e8f0;
  --sf-sidebar-bg: #1e293b;
  --sf-sidebar-text: #94a3b8;
  --sf-sidebar-active: #4f46e5;
}

[data-theme="dark"] {
  --sf-bg: #0f172a;
  --sf-card-bg: #1e293b;
  --sf-text: #e2e8f0;
  --sf-text-muted: #94a3b8;
  --sf-border: #334155;
}

* { box-sizing: border-box; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--sf-bg);
  color: var(--sf-text);
  margin: 0;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

/* ==================== SIDEBAR ==================== */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sf-sidebar-width);
  height: 100vh;
  background: var(--sf-sidebar-bg);
  color: var(--sf-sidebar-text);
  z-index: 1030;
  transition: width 0.3s ease, transform 0.3s ease;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

.sidebar.collapsed { width: var(--sf-sidebar-collapsed); }

.sidebar .sidebar-brand {
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  height: var(--sf-topbar-height);
  position: sticky;
  top: 0;
  background: var(--sf-sidebar-bg);
  z-index: 1;
}

.sidebar .sidebar-brand img { height: 36px; width: 36px; object-fit: contain; border-radius: 8px; }
.sidebar .sidebar-brand span { font-size: 1.1rem; font-weight: 700; color: #fff; white-space: nowrap; }

.sidebar.collapsed .sidebar-brand span { display: none; }

.sidebar-nav { padding: 0.5rem 0; padding-bottom: 2rem; }

.sidebar-nav .nav-section {
  padding: 0.75rem 1.25rem 0.25rem;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #475569;
  white-space: nowrap;
}

.sidebar.collapsed .nav-section { display: none; }

.sidebar-nav .nav-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 1.25rem;
  color: var(--sf-sidebar-text);
  text-decoration: none;
  font-size: 0.875rem;
  border-radius: 0.375rem;
  margin: 0.125rem 0.5rem;
  transition: all 0.2s;
  white-space: nowrap;
}

.sidebar-nav .nav-link:hover {
  background: rgba(255,255,255,0.08);
  color: #e2e8f0;
}

.sidebar-nav .nav-link.active {
  background: var(--sf-sidebar-active);
  color: #fff;
}

.sidebar-nav .nav-link i { font-size: 1.1rem; width: 24px; text-align: center; flex-shrink: 0; }
.sidebar-nav .nav-link span { white-space: nowrap; }
.sidebar.collapsed .nav-link span { display: none; }
.sidebar.collapsed .nav-link { justify-content: center; padding: 0.6rem; }

/* ==================== MAIN CONTENT ==================== */
.main-content {
  margin-left: var(--sf-sidebar-width);
  min-height: 100vh;
  min-height: 100dvh;
  transition: margin-left 0.3s ease;
}

.sidebar.collapsed ~ .main-content { margin-left: var(--sf-sidebar-collapsed); }

/* ==================== TOPBAR ==================== */
.topbar {
  height: var(--sf-topbar-height);
  background: var(--sf-card-bg);
  border-bottom: 1px solid var(--sf-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  position: sticky;
  top: 0;
  z-index: 1020;
}

.topbar .btn-toggle-sidebar {
  background: none;
  border: none;
  color: var(--sf-text);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.25rem;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.topbar .user-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.topbar .user-info .user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--sf-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.875rem;
  flex-shrink: 0;
}

/* ==================== CONTENT ==================== */
.content-wrapper {
  padding: 1.5rem;
}

.card {
  border-radius: 0.5rem;
  border: 1px solid var(--sf-border);
  background: var(--sf-card-bg);
}

.card-header {
  border-bottom: 1px solid var(--sf-border);
  background: transparent;
}

.table { --bs-table-bg: transparent; }
.table thead th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; }

.form-control, .form-select {
  border-radius: 0.375rem;
  border-color: var(--sf-border);
  font-size: 0.875rem;
}

.btn { border-radius: 0.375rem; font-size: 0.875rem; }
.badge { font-weight: 500; font-size: 0.75rem; }

.chart-container { position: relative; height: 300px; width: 100%; }

.page-link { border-radius: 0.25rem; margin: 0 0.125rem; }

.modal-content { border-radius: 0.75rem; border: none; }
.modal-header { border-bottom: 1px solid var(--sf-border); }
.modal-footer { border-top: 1px solid var(--sf-border); }

#toast-container { z-index: 9999; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }

.sortable:hover { background: rgba(255,255,255,0.1); }

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

/* ==================== PAGE HEADER ==================== */
.page-header-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}

/* ==================== STAT CARDS ==================== */
.stat-card-value {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.2;
}

/* ==================== TABLE RESPONSIVE ==================== */
.table-responsive {
  border-radius: 0.5rem;
  -webkit-overflow-scrolling: touch;
}

.table-responsive > .table {
  min-width: 600px;
}

.table td, .table th {
  vertical-align: middle;
  white-space: nowrap;
}

.table td.wrap { white-space: normal; word-break: break-word; }

/* ==================== TOUCH TARGETS ==================== */
.btn, .form-control, .form-select, .nav-link, .page-link {
  min-height: 44px;
}

.form-control-sm, .form-select-sm, .btn-sm {
  min-height: 36px;
}

/* ==================== MOBILE: TABLET & BELOW ==================== */
@media (max-width: 991.98px) {
  .sidebar {
    transform: translateX(-100%);
    width: 280px;
  }

  .sidebar.show {
    transform: translateX(0);
    box-shadow: 4px 0 20px rgba(0,0,0,0.3);
  }

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

  .sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1025;
    display: none;
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
  }

  .sidebar-overlay.show { display: block; }

  .topbar {
    padding: 0 1rem;
  }

  .topbar #pageTitle {
    font-size: 0.95rem;
  }

  .content-wrapper {
    padding: 1rem;
  }
}

/* ==================== MOBILE: SMALL PHONES ==================== */
@media (max-width: 575.98px) {
  :root {
    --sf-topbar-height: 52px;
  }

  .content-wrapper {
    padding: 0.75rem;
  }

  .topbar {
    padding: 0 0.75rem;
  }

  .topbar #pageTitle {
    font-size: 0.85rem;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .page-header-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .page-header-actions .d-flex {
    justify-content: stretch;
  }

  .page-header-actions .btn {
    flex: 1;
  }

  .card-body {
    padding: 0.75rem;
  }

  .card-body.p-0 {
    padding: 0 !important;
  }

  .chart-container {
    height: 220px;
  }

  .stat-card-value {
    font-size: 1.25rem;
  }

  .stat-card-value + small,
  .stat-card-value ~ small {
    font-size: 0.7rem;
  }

  .table {
    font-size: 0.8rem;
  }

  .table thead th {
    font-size: 0.7rem;
    padding: 0.5rem;
  }

  .table td {
    padding: 0.5rem;
    font-size: 0.8rem;
  }

  .modal-dialog {
    margin: 0.5rem;
    max-width: calc(100% - 1rem);
  }

  .modal-body {
    padding: 0.75rem;
  }

  .modal-body .form-label {
    font-size: 0.8rem;
  }

  .modal-body .form-control,
  .modal-body .form-select {
    font-size: 0.85rem;
    padding: 0.5rem 0.75rem;
  }

  .pagination {
    flex-wrap: wrap;
    gap: 0.125rem;
  }

  .page-link {
    padding: 0.35rem 0.6rem;
    font-size: 0.8rem;
    min-width: 36px;
    text-align: center;
  }

  .dropdown-menu {
    min-width: 180px;
  }

  .login-card {
    width: 100% !important;
    max-width: 100% !important;
    margin: 1rem;
  }

  .login-card .card-body {
    padding: 1.5rem;
  }

  #toast-container {
    top: 0.5rem !important;
    right: 0.5rem !important;
    left: 0.5rem;
  }

  .toast {
    width: 100%;
    font-size: 0.85rem;
  }
}

/* ==================== MOBILE: LANDSCAPE PHONE ==================== */
@media (max-width: 575.98px) and (orientation: landscape) {
  .chart-container {
    height: 180px;
  }

  .modal-body {
    max-height: 70vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* ==================== TABLET LANDSCAPE ==================== */
@media (min-width: 768px) and (max-width: 991.98px) {
  .content-wrapper {
    padding: 1.25rem;
  }

  .chart-container {
    height: 260px;
  }
}

/* ==================== LARGE SCREENS ==================== */
@media (min-width: 1400px) {
  .content-wrapper {
    max-width: 1400px;
    margin: 0 auto;
  }
}

/* ==================== PRINT ==================== */
@media print {
  .sidebar, .topbar, .sidebar-overlay { display: none !important; }
  .main-content { margin-left: 0 !important; }
  .content-wrapper { padding: 0; }
  .card { border: none; box-shadow: none; }
  .btn { display: none; }
}

/* ==================== UTILITY: SAFE AREA (iOS) ==================== */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .content-wrapper {
    padding-bottom: calc(1.5rem + env(safe-area-inset-bottom));
  }
  .sidebar {
    height: calc(100vh - env(safe-area-inset-top));
  }
}

/* ==================== REDUCED MOTION ==================== */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ==================== NO HOVER (TOUCH DEVICES) ==================== */
@media (hover: none) and (pointer: coarse) {
  .btn:hover, .nav-link:hover, .page-link:hover {
    transform: none;
  }

  .sidebar-nav .nav-link:active {
    background: rgba(255,255,255,0.12);
  }
}
