/* ==========================================================================
   Chaplain's Shield — Clean & Lightweight Admin Design System
   No heavy gradients, no blurs, minimal bundle size, fully responsive.
   ========================================================================== */

:root {
  --bg-base: #0f172a;
  --bg-sidebar: #1e293b;
  --bg-card: #1e293b;
  --bg-input: #0f172a;
  --bg-hover: #334155;

  --border: #334155;
  --border-light: #475569;

  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-faint: #64748b;

  --primary: #2563eb;
  --primary-hover: #1d4ed8;

  --success: #16a34a;
  --success-bg: rgba(22, 163, 74, 0.15);
  --warning: #d97706;
  --warning-bg: rgba(217, 119, 6, 0.15);
  --danger: #dc2626;
  --danger-bg: rgba(220, 38, 38, 0.15);
  --info: #0284c7;
  --info-bg: rgba(2, 132, 199, 0.15);

  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-base);
  color: var(--text-main);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ==========================================================================
   AUTH SCREEN (LOGIN)
   ========================================================================== */
.auth-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
  background-color: var(--bg-base);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem;
}

.auth-header {
  text-align: center;
  margin-bottom: 1.5rem;
}

.brand-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  background: var(--primary);
  border-radius: var(--radius-md);
  margin-bottom: 1rem;
}

.brand-badge svg {
  width: 24px;
  height: 24px;
  color: white;
}

.auth-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.auth-subtitle {
  color: var(--text-muted);
  font-size: 0.8125rem;
}

.form-group {
  margin-bottom: 1rem;
}

.form-label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.input-container {
  position: relative;
  display: flex;
  align-items: center;
}

.input-icon {
  position: absolute;
  left: 0.75rem;
  width: 16px;
  height: 16px;
  color: var(--text-faint);
  pointer-events: none;
}

.form-input, .form-textarea, .form-select {
  width: 100%;
  padding: 0.625rem 0.75rem 0.625rem 2.25rem;
  background-color: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-main);
  font-size: 0.875rem;
  font-family: inherit;
  outline: none;
}

.form-input.no-icon, .form-textarea, .form-select {
  padding-left: 0.75rem;
}

.form-input:focus, .form-textarea:focus, .form-select:focus {
  border-color: var(--primary);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.625rem 1rem;
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  line-height: 1.2;
}

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

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

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

.btn-secondary:hover {
  background: var(--bg-hover);
  border-color: var(--border-light);
}

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

.btn-danger:hover {
  background: #b91c1c;
}

.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.75rem;
  border-radius: var(--radius-sm);
}

.btn-block {
  width: 100%;
}

.auth-config-toggle {
  margin-top: 1rem;
  font-size: 0.75rem;
  color: var(--text-faint);
  text-align: center;
  cursor: pointer;
}

.auth-config-toggle:hover {
  color: var(--text-muted);
}

.config-box {
  margin-top: 0.5rem;
  padding: 0.75rem;
  background: var(--bg-input);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  display: none;
}

.config-box.open {
  display: block;
}

/* ==========================================================================
   APP LAYOUT (RESPONSIVE)
   ========================================================================== */
.app-container {
  display: flex;
  min-height: 100vh;
}

/* Backdrop for mobile drawer */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 99;
}

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

/* Sidebar */
.sidebar {
  width: 240px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 100;
  transition: transform 0.2s ease-in-out;
}

.sidebar-header {
  padding: 1.25rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.sidebar-brand-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  flex-shrink: 0;
}

.sidebar-brand-text h2 {
  font-size: 0.9375rem;
  font-weight: 700;
}

.sidebar-brand-text span {
  font-size: 0.6875rem;
  color: var(--text-faint);
  text-transform: uppercase;
}

.sidebar-nav {
  padding: 1rem 0.5rem;
  flex: 1;
  overflow-y: auto;
}

.nav-section-title {
  font-size: 0.6875rem;
  font-weight: 700;
  color: var(--text-faint);
  text-transform: uppercase;
  padding: 0 0.5rem 0.35rem 0.5rem;
  margin-top: 0.5rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.625rem 0.75rem;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.8125rem;
  font-weight: 500;
  margin-bottom: 0.2rem;
  cursor: pointer;
}

.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text-main);
}

.nav-item.active {
  background: #2563eb26;
  color: #93c5fd;
  border-left: 3px solid var(--primary);
}

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

.nav-counter {
  margin-left: auto;
  font-size: 0.6875rem;
  font-weight: 600;
  background: var(--bg-input);
  padding: 0.1rem 0.4rem;
  border-radius: 9999px;
  color: var(--text-muted);
}

.sidebar-footer {
  padding: 0.875rem 1rem;
  border-top: 1px solid var(--border);
  background: #0b1220;
}

.admin-badge {
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

.admin-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: white;
  font-size: 0.8125rem;
  flex-shrink: 0;
}

.admin-info {
  flex: 1;
  overflow: hidden;
}

.admin-name {
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.admin-role {
  font-size: 0.6875rem;
  color: var(--success);
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.status-dot {
  width: 6px;
  height: 6px;
  background-color: var(--success);
  border-radius: 50%;
  display: inline-block;
}

/* Main Wrapper */
.main-wrapper {
  flex: 1;
  margin-left: 240px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-width: 0;
}

.topbar {
  height: 56px;
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  position: sticky;
  top: 0;
  z-index: 90;
}

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

.hamburger-btn {
  display: none;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 0.4rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  align-items: center;
  justify-content: center;
}

.hamburger-btn svg {
  width: 18px;
  height: 18px;
}

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

.env-pill {
  font-size: 0.75rem;
  font-weight: 500;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  background: var(--bg-input);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.content-body {
  padding: 1.5rem;
  flex: 1;
}

/* Section Header */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.section-title h1 {
  font-size: 1.25rem;
  font-weight: 700;
}

.section-title p {
  color: var(--text-muted);
  font-size: 0.8125rem;
  margin-top: 0.15rem;
}

/* Action Bar */
.action-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.search-box {
  position: relative;
  width: 280px;
}

.search-box input {
  padding-left: 2rem;
  padding-top: 0.45rem;
  padding-bottom: 0.45rem;
  font-size: 0.8125rem;
}

.search-box svg {
  position: absolute;
  left: 0.65rem;
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  color: var(--text-faint);
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}

/* ==========================================================================
   DATA TABLE & CARDS
   ========================================================================== */
.data-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.8125rem;
  white-space: nowrap;
}

.data-table th {
  padding: 0.75rem 1rem;
  background: #0f172a;
  color: var(--text-muted);
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table tr:last-child td {
  border-bottom: none;
}

.data-table tr:hover td {
  background: var(--bg-hover);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  font-size: 0.6875rem;
  font-weight: 600;
}

.badge-success {
  background: var(--success-bg);
  color: #4ade80;
  border: 1px solid #16a34a40;
}

.badge-warning {
  background: var(--warning-bg);
  color: #fbbf24;
  border: 1px solid #d9770640;
}

.badge-danger {
  background: var(--danger-bg);
  color: #f87171;
  border: 1px solid #dc262640;
}

.badge-info {
  background: var(--info-bg);
  color: #38bdf8;
  border: 1px solid #0284c740;
}

.badge-neutral {
  background: var(--bg-input);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

/* File pill */
.file-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
}

.file-pill svg {
  width: 14px;
  height: 14px;
  color: var(--primary);
  flex-shrink: 0;
}

.table-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.action-icon-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.3rem;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}

.action-icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text-main);
}

.action-icon-btn.danger:hover {
  background: var(--danger-bg);
  color: var(--danger);
}

/* ==========================================================================
   REPORTS GRID
   ========================================================================== */
.reports-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}

.report-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
}

.report-card:hover {
  border-color: var(--border-light);
}

.report-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.report-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
}

.report-date {
  font-size: 0.75rem;
  color: var(--text-faint);
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.report-desc {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
  flex: 1;
}

.report-files-summary {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

/* ==========================================================================
   MODALS & POPUPS
   ========================================================================== */
body.modal-open {
  overflow: hidden !important;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1.25rem 1rem;
  opacity: 0;
  pointer-events: none;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  transition: opacity 0.2s ease;
}

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

.modal-content {
  width: 100%;
  max-width: 540px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 2.5rem);
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.6), 0 10px 10px -5px rgba(0, 0, 0, 0.4);
  position: relative;
  overflow: hidden;
  margin: auto;
  box-sizing: border-box;
}

.modal-content.modal-lg {
  max-width: 700px;
}

/* Form inside modal must be flex column with min-height: 0 to enable scrolling */
.modal-content > form,
#docForm,
#volForm,
#reportForm {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  box-sizing: border-box;
}

.modal-header {
  padding: 1.125rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-card);
  flex-shrink: 0;
  z-index: 5;
}

.modal-header h3 {
  font-size: 1.0625rem;
  font-weight: 600;
  color: var(--text-main);
}

.modal-close-btn {
  background: transparent;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 1.5rem;
  line-height: 1;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
  transition: color 0.15s, background 0.15s;
}

.modal-close-btn:hover {
  color: var(--text-main);
  background: var(--bg-hover);
}

.modal-body {
  padding: 1.25rem;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1;
  min-height: 0;
  overscroll-behavior: contain;
  box-sizing: border-box;
}

.modal-footer {
  padding: 0.875rem 1.25rem;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  background: var(--bg-card);
  flex-shrink: 0;
  position: sticky;
  bottom: 0;
  z-index: 10;
  box-shadow: 0 -4px 10px rgba(0, 0, 0, 0.2);
}

/* Responsive 2-column form grids */
.form-grid-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  width: 100%;
  box-sizing: border-box;
}

.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-md);
  padding: 1.25rem 1rem;
  text-align: center;
  background: var(--bg-input);
  cursor: pointer;
  display: block;
  width: 100%;
  box-sizing: border-box;
  overflow: hidden;
  transition: border-color 0.2s, background 0.2s;
}

.dropzone:hover {
  border-color: var(--primary);
  background: rgba(37, 99, 235, 0.05);
}

.dropzone svg {
  width: 28px;
  height: 28px;
  color: var(--primary);
  margin-bottom: 0.35rem;
}

.dropzone-text {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-main);
  margin-top: 0.25rem;
  word-break: break-word;
  overflow-wrap: anywhere;
  max-width: 100%;
  line-height: 1.4;
}

.dropzone-hint {
  font-size: 0.6875rem;
  color: var(--text-faint);
  margin-top: 0.25rem;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.file-preview-card {
  padding: 0.625rem 0.75rem;
  background: var(--bg-input);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  margin-bottom: 0.75rem;
  width: 100%;
  box-sizing: border-box;
  overflow: hidden;
}

.file-preview-card * {
  max-width: 100%;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.attachment-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.75rem;
  width: 100%;
  box-sizing: border-box;
}

.attachment-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.625rem 0.75rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 0.75rem;
  width: 100%;
  box-sizing: border-box;
  max-width: 100%;
  overflow: hidden;
}

.attachment-item-info {
  flex: 1;
  min-width: 0; /* CRITICAL: Enables ellipsis in flex items */
  overflow: hidden;
}

.attachment-item-name {
  font-weight: 600;
  color: var(--text-main);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-kind-select {
  flex-shrink: 0;
  max-width: 120px;
  padding: 0.35rem 0.5rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-size: 0.75rem;
  cursor: pointer;
}

/* Toast */
.toast-container {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 2000;
  pointer-events: none;
}

.toast {
  padding: 0.75rem 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-main);
  font-size: 0.8125rem;
  pointer-events: auto;
  max-width: 320px;
}

.toast.toast-success {
  border-left: 3px solid var(--success);
}

.toast.toast-error {
  border-left: 3px solid var(--danger);
}

.toast.toast-info {
  border-left: 3px solid var(--info);
}

.token-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.code-snippet {
  background: #090e17;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.625rem;
  font-family: monospace;
  font-size: 0.75rem;
  color: #93c5fd;
  overflow-x: auto;
  word-break: break-all;
}

/* ==========================================================================
   RESPONSIVE BREAKPOINTS (Desktop, Laptop, Tablet, Mobile)
   ========================================================================== */

/* Laptop (1024px to 1280px) */
@media (max-width: 1280px) {
  .reports-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Tablet (768px to 1024px) */
@media (max-width: 1024px) {
  .sidebar {
    transform: translateX(-100%);
  }

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

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

  .hamburger-btn {
    display: inline-flex;
  }

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

  .content-body {
    padding: 1.25rem;
  }
}

/* Mobile (< 768px) */
@media (max-width: 768px) {
  html, body {
    overflow-x: hidden;
  }

  .app-container {
    overflow-x: hidden;
    width: 100%;
  }

  .main-wrapper {
    margin-left: 0;
    overflow-x: hidden;
    width: 100%;
    min-width: 0;
  }

  .topbar {
    padding: 0 1rem;
  }

  .content-body {
    padding: 1rem 0.75rem;
    overflow-x: hidden;
  }

  .section-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }

  .section-header .btn {
    width: 100%;
  }

  .action-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }

  .search-box {
    width: 100%;
  }

  .filter-group {
    width: 100%;
    justify-content: flex-start;
    overflow-x: auto;
    padding-bottom: 0.25rem;
  }

  .reports-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .data-table th, .data-table td {
    padding: 0.625rem 0.5rem;
    font-size: 0.8125rem;
  }

  .modal-backdrop {
    padding: 0.5rem;
    align-items: flex-end; /* Mobile bottom-sheet anchoring */
  }

  .modal-content {
    max-height: 94vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    margin: 0;
  }

  .modal-header {
    padding: 0.875rem 1rem;
  }

  .modal-body {
    padding: 1rem;
  }

  .modal-footer {
    padding: 0.75rem 1rem;
    flex-direction: row; /* Keep Cancel and Save side-by-side */
    gap: 0.5rem;
  }

  .modal-footer .btn {
    flex: 1;
    min-width: 0;
    padding: 0.625rem 0.5rem;
    font-size: 0.8125rem;
  }

  .attachment-item {
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.5rem 0.625rem;
  }

  .attachment-item-info {
    width: calc(100% - 32px);
    flex: none;
  }

  .attachment-kind-select {
    flex: 1;
    max-width: none;
  }

  .toast-container {
    left: 1rem;
    right: 1rem;
    bottom: 1rem;
  }

  .toast {
    max-width: 100%;
  }
}
