/* ── Global Styles & Design Tokens ── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg-deep:    #060d1a;
  --bg-dark:    #0d1b2e;
  --bg-card:    rgba(13, 27, 46, 0.65);
  --border:     rgba(255, 255, 255, 0.08);
  --border-hover: rgba(99, 102, 241, 0.4);
  --accent:     #6366f1;
  --accent-glow: rgba(99, 102, 241, 0.25);
  --accent-light: #a5b4fc;
  --green:      #10b981;
  --green-glow: rgba(16, 185, 129, 0.15);
  --yellow:     #f59e0b;
  --yellow-glow: rgba(245, 158, 11, 0.15);
  --red:        #ef4444;
  --red-glow:   rgba(239, 68, 68, 0.15);
  
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #475569;
  --text-heading: #ffffff;
  
  --font-family: 'Sarabun', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --grid-color: rgba(255, 255, 255, 0.007);
  --input-bg: rgba(4, 8, 17, 0.5);
  --input-bg-focus: rgba(4, 8, 17, 0.7);
}

body.light-theme {
  --bg-deep:    #f8fafc;
  --bg-dark:    #ffffff;
  --bg-card:    rgba(255, 255, 255, 0.85);
  --border:     rgba(15, 23, 42, 0.08);
  --border-hover: rgba(99, 102, 241, 0.6);
  --accent:     #4f46e5;
  --accent-glow: rgba(99, 102, 241, 0.1);
  --accent-light: #6366f1;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --text-heading: #0f172a;
  --grid-color: rgba(15, 23, 42, 0.02);
  --input-bg: #ffffff;
  --input-bg-focus: #f1f5f9;
}

html, body {
  min-height: 100vh;
  font-family: var(--font-family);
  background-color: var(--bg-deep);
  color: var(--text-primary);
  overflow-x: hidden;
}

/* ── Background Orbs & Grid ── */
.bg-grid {
  position: fixed;
  inset: 0;
  z-index: 0;
  background-image:
    linear-gradient(var(--grid-color) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-color) 1px, transparent 1px);
  background-size: 50px 50px;
  pointer-events: none;
}

.bg-orb {
  position: fixed;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.3;
  z-index: 0;
  pointer-events: none;
  transform: translateZ(0);
}

.bg-orb-1 {
  width: 500px;
  height: 500px;
  background: radial-gradient(circle, var(--accent), transparent 70%);
  top: -150px;
  left: -100px;
}

.bg-orb-2 {
  width: 450px;
  height: 450px;
  background: radial-gradient(circle, #0d9488, transparent 70%);
  bottom: -100px;
  right: -80px;
}

/* ── Typography & Components ── */
h1, h2, h3, h4 {
  font-weight: 700;
  color: var(--text-heading);
  letter-spacing: -0.01em;
}

.required {
  color: var(--red);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-family);
  font-size: 0.95rem;
  font-weight: 600;
  padding: 10px 24px;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: var(--transition);
  gap: 8px;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent) 0%, #4f46e5 100%);
  color: #fff;
  box-shadow: 0 4px 14px var(--accent-glow);
}
.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}
.btn-primary:active {
  transform: translateY(0);
}

.btn-outline {
  background: transparent;
  color: var(--text-primary);
  border-color: var(--border);
}
.btn-outline:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--text-secondary);
}

.btn-outline-danger {
  background: transparent;
  color: #f87171;
  border-color: rgba(239, 68, 68, 0.3);
}
.btn-outline-danger:hover {
  background: rgba(239, 68, 68, 0.1);
  border-color: var(--red);
}

.btn-sm {
  padding: 6px 14px;
  font-size: 0.85rem;
  border-radius: 8px;
}

.btn-block {
  width: 100%;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

/* Card layout */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 30px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  margin-bottom: 25px;
}

.card-title {
  font-size: 1.3rem;
  margin-bottom: 24px;
  position: relative;
  padding-bottom: 10px;
}
.card-title::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 40px;
  height: 3px;
  background: var(--accent);
  border-radius: 2px;
}

.card-header-flex {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}
.card-header-flex .card-title {
  margin-bottom: 0;
}

/* ── Password Gate Overlay ── */
.password-gate {
  position: fixed;
  inset: 0;
  background-color: #040811;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.password-card {
  width: 100%;
  max-width: 400px;
  background: rgba(13, 27, 46, 0.8);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 35px;
  backdrop-filter: blur(16px);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
  text-align: center;
}

.password-card .logo-area {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 15px;
}

.password-card .logo-icon {
  font-size: 2rem;
  background: linear-gradient(135deg, var(--accent), #818cf8);
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.password-card h2 {
  font-size: 1.5rem;
}

.password-card h3 {
  font-size: 1.1rem;
  color: var(--accent-light);
  margin-bottom: 8px;
}

.gate-desc {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 25px;
}

.error-text {
  color: #f87171;
  font-size: 0.85rem;
  margin-top: 10px;
  font-weight: 500;
}

/* ── App Layout ── */
.app-wrapper {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  max-width: 1000px;
  margin: 0 auto;
  padding: 0 20px;
}

.app-header {
  border-bottom: 1px solid var(--border);
  padding: 20px 0;
  margin-bottom: 30px;
}

.header-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.brand {
  display: flex;
  align-items: center;
  gap: 15px;
}

.brand-icon {
  font-size: 1.8rem;
  background: linear-gradient(135deg, var(--accent), #818cf8);
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 20px var(--accent-glow);
}

.brand-text h1 {
  font-size: 1.25rem;
  font-weight: 800;
}

.brand-text p {
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.app-main {
  flex: 1;
}

/* ── Tabs Navigation ── */
.tabs-nav {
  display: flex;
  gap: 10px;
  margin-bottom: 24px;
}

.tab-btn {
  font-family: var(--font-family);
  background: rgba(13, 27, 46, 0.4);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 12px 24px;
  font-weight: 600;
  font-size: 0.95rem;
  border-radius: 12px;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 8px;
}

.tab-btn:hover {
  background: rgba(255, 255, 255, 0.04);
  color: #fff;
}

.tab-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 4px 15px var(--accent-glow);
}

.tab-pane {
  display: none;
}
.tab-pane.active {
  display: block;
  animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Form Controls ── */
.form-group {
  margin-bottom: 22px;
}

.form-row {
  display: flex;
  gap: 20px;
}
.form-row .form-group {
  flex: 1;
}

.form-label {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.form-control {
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: 0.95rem;
  padding: 12px 16px;
  border-radius: 10px;
  transition: var(--transition);
}

.form-control:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 10px rgba(99, 102, 241, 0.2);
  background: var(--input-bg-focus);
}

.form-control::placeholder {
  color: var(--text-muted);
}

/* ── File Upload / Dropzone ── */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 30px;
  text-align: center;
  background: rgba(255, 255, 255, 0.01);
  cursor: pointer;
  transition: var(--transition);
  position: relative;
}

.upload-zone:hover, .upload-zone.dragover {
  border-color: var(--accent);
  background: rgba(99, 102, 241, 0.03);
}

.file-hidden {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 10;
}

.upload-icon {
  font-size: 2.2rem;
  display: block;
  margin-bottom: 12px;
}

.upload-prompt p {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.upload-sub {
  font-size: 0.78rem;
  color: var(--text-secondary);
}

/* Thumbnail Previews */
.preview-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 12px;
  margin-top: 15px;
}

.preview-item {
  position: relative;
  width: 100px;
  height: 100px;
  border-radius: 10px;
  border: 1px solid var(--border);
  overflow: hidden;
  background: #000;
}

.preview-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.preview-item .remove-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(239, 68, 68, 0.85);
  color: #fff;
  border: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  font-size: 0.8rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}
.preview-item .remove-btn:hover {
  background: var(--red);
}

/* File list for documents */
.file-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 15px;
}

.file-list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(255, 255, 255, 0.03);
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.file-list-item .file-name {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.file-list-item .remove-file-btn {
  color: #f87171;
  background: none;
  border: none;
  font-size: 0.85rem;
  cursor: pointer;
}

/* Progress bar styles */
.progress-wrapper {
  margin-top: 20px;
}
.progress-text {
  font-size: 0.85rem;
  color: var(--text-secondary);
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
}
.progress-bar-container {
  height: 8px;
  background: rgba(255,255,255,0.05);
  border-radius: 4px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), #10b981);
  border-radius: 4px;
  transition: width 0.1s linear;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 30px;
}

/* ── History Table & Grid ── */
.card-wide {
  width: 100%;
}

.table-container {
  width: 100%;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.data-table th, .data-table td {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.data-table th {
  font-weight: 700;
  font-size: 0.85rem;
  text-transform: uppercase;
  color: var(--text-secondary);
  letter-spacing: 0.05em;
  background: rgba(255, 255, 255, 0.01);
}

.data-table tbody tr {
  transition: var(--transition);
}

.data-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.015);
}

.table-loading {
  text-align: center;
  color: var(--text-secondary);
  padding: 40px !important;
}

/* Item details inside table */
.history-title {
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  margin-bottom: 4px;
}

.history-desc {
  font-size: 0.85rem;
  color: var(--text-secondary);
  white-space: pre-line;
}

.history-date {
  font-family: 'Inter', sans-serif;
  font-size: 0.9rem;
  color: var(--text-primary);
  font-weight: 500;
}

/* History Media Previews */
.history-images {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.history-img-thumb {
  width: 44px;
  height: 44px;
  border-radius: 6px;
  object-fit: cover;
  cursor: pointer;
  border: 1px solid var(--border);
  transition: var(--transition);
}
.history-img-thumb:hover {
  transform: scale(1.08);
  border-color: var(--accent);
}

.history-files {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.history-file-link {
  font-size: 0.8rem;
  color: var(--accent-light);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.history-file-link:hover {
  color: #fff;
  text-decoration: underline;
}

/* Status Badges */
.badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 6px;
  gap: 5px;
}

.badge-success {
  background: var(--green-glow);
  color: var(--green);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.badge-warning {
  background: var(--yellow-glow);
  color: var(--yellow);
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.badge-danger {
  background: var(--red-glow);
  color: var(--red);
  border: 1px solid rgba(239, 68, 68, 0.3);
  cursor: help;
}

/* ── Lightbox Modal ── */
.lightbox {
  display: none;
  position: fixed;
  z-index: 2000;
  inset: 0;
  background-color: rgba(4, 8, 17, 0.95);
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.lightbox-content {
  max-width: 90%;
  max-height: 80vh;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.8);
  animation: zoom 0.25s ease-out;
}

@keyframes zoom {
  from { transform: scale(0.95); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.lightbox-close {
  position: absolute;
  top: 25px;
  right: 30px;
  color: var(--text-secondary);
  font-size: 2.5rem;
  font-weight: 300;
  cursor: pointer;
  transition: var(--transition);
}
.lightbox-close:hover {
  color: #fff;
}

.lightbox-caption {
  position: absolute;
  bottom: 40px;
  color: var(--text-secondary);
  font-size: 0.95rem;
}

/* ── Toast Notification ── */
.toast {
  position: fixed;
  bottom: -60px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(13, 27, 46, 0.95);
  border: 1px solid var(--border);
  color: #fff;
  padding: 12px 24px;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 600;
  z-index: 3000;
  transition: bottom 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
}

.toast.show {
  bottom: 30px;
}

/* ── Footer ── */
.app-footer {
  text-align: center;
  padding: 40px 0;
  font-size: 0.78rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  margin-top: 50px;
}

/* Responsive adjustment */
@media(max-width: 600px) {
  .form-row {
    flex-direction: column;
    gap: 0;
  }
  
  .app-header .header-container {
    flex-direction: column;
    gap: 15px;
    text-align: center;
    align-items: center;
  }
  
  .brand {
    flex-direction: column;
    text-align: center;
  }
  
  .tabs-nav {
    flex-direction: column;
  }
  
  .tab-btn {
    justify-content: center;
  }
}
