/* ============================================
   Yuki CODA Downloader — Modern UI Refresh
   Based on Kimi K2.5 design proposal
   ============================================ */

/* --- Design Tokens --- */
:root {
  /* Primary — Modern Blue */
  --color-primary: #2563eb;
  --color-primary-dark: #1d4ed8;
  --color-primary-light: #dbeafe;
  --color-primary-subtle: #eff6ff;

  /* Neutrals — Warmer gray scale */
  --color-gray-50: #f8fafc;
  --color-card-bg: #ffffff;
  --color-gray-100: #f1f5f9;
  --color-gray-200: #e2e8f0;
  --color-gray-300: #cbd5e1;
  --color-gray-400: #94a3b8;
  --color-gray-500: #64748b;
  --color-gray-600: #475569;
  --color-gray-700: #334155;
  --color-gray-800: #1e293b;
  --color-gray-900: #0f172a;

  /* Semantic — Gedempt maar duidelijk */
  --color-success: #10b981;
  --color-success-light: #ecfdf5;
  --color-error: #ef4444;
  --color-error-light: #fef2f2;
  --color-warning: #f59e0b;
  --color-warning-light: #fef3c7;
  --color-info: #3b82f6;
  --color-info-light: #eff6ff;

  /* Typography */
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
  --font-mono: 'SF Mono', ui-monospace, 'Menlo', monospace;

  /* Spacing — 4px scale */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 12px;
  --space-base: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;

  /* Shadows — Subtiele depth */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);

  /* Radii */
  --radius-sm: 6px;
  --radius-default: 10px;
  --radius-lg: 14px;
  --radius-dialog: 16px;
}

/* --- Reset & Base --- */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  font-weight: 400;
  background: var(--color-gray-100);
  color: var(--color-gray-700);
  min-height: 100vh;
  line-height: 1.6;
}

/* --- App Shell --- */
.app-header {
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
  padding: var(--space-base) var(--space-lg);
  color: white;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow-md);
}

.app-header-inner {
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.app-logo {
  width: 36px;
  height: 36px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-default);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 1rem;
  flex-shrink: 0;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.app-header h1 {
  font-size: 1.125rem;
  font-weight: 600;
  color: white;
  margin: 0;
  letter-spacing: -0.01em;
}

.header-subtitle-row {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.app-header .header-subtitle-row {
  font-size: 0.8125rem;
  opacity: 0.85;
  font-weight: 400;
  margin-top: 2px;
}

.btn-info {
  font-size: 0.65rem;
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-default);
  background: rgba(255, 255, 255, 0.2);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.3);
  cursor: pointer;
  font-weight: 400;
  opacity: 1;
  transition: background 0.15s ease;
}

.btn-info:hover {
  background: rgba(255, 255, 255, 0.35);
}

.container {
  max-width: 1250px;
  margin: 0 auto;
  padding: var(--space-lg) var(--space-lg);
}

/* --- Cards — White with subtle shadow --- */
.card {
  background: white;
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  margin-bottom: var(--space-lg);
  border: 1px solid var(--color-gray-200);
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s ease;
}

.card:hover {
  box-shadow: var(--shadow-md);
}

.card h2 {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--color-gray-900);
  margin-bottom: var(--space-lg);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.card h2::before {
  content: '';
  display: inline-block;
  width: 4px;
  height: 18px;
  background: var(--color-primary);
  border-radius: 2px;
}

/* --- Section Header --- */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-base);
  gap: var(--space-md);
}

.section-header h2 {
  margin-bottom: 0;
}

/* --- Form Elements --- */
.form-group {
  margin-bottom: var(--space-base);
}

.form-group label {
  display: block;
  margin-bottom: var(--space-sm);
  font-weight: 500;
  font-size: 0.875rem;
  color: var(--color-gray-700);
}

.hint {
  color: var(--color-gray-400);
  font-weight: 400;
  font-size: 0.8rem;
}

input[type="text"],
input[type="password"],
input[type="date"] {
  width: 100%;
  padding: 0.625rem 0.875rem;
  border: 1px solid var(--color-gray-300);
  border-radius: var(--radius-default);
  font-size: 0.9375rem;
  font-family: var(--font-sans);
  font-weight: 400;
  color: var(--color-gray-800);
  background: white;
  line-height: 1.5;
  transition: all 0.15s ease;
}

input[type="text"]::placeholder,
input[type="password"]::placeholder {
  color: var(--color-gray-400);
}

input[type="text"]:hover,
input[type="password"]:hover,
input[type="date"]:hover {
  border-color: var(--color-gray-400);
}

input[type="text"]:focus,
input[type="password"]:focus,
input[type="date"]:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-light);
}

/* Checkbox styling */
input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--color-primary);
  cursor: pointer;
}

/* --- Buttons --- */
button {
  font-family: var(--font-sans);
  font-weight: 500;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  line-height: 1;
  transition: all 0.15s ease;
}

/* Primary button with subtle gradient */
.btn-primary,
#connectBtn,
#downloadBtn {
  background: linear-gradient(180deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
  color: white;
  padding: 0.65rem 1.25rem;
  border-radius: var(--radius-default);
  font-size: 0.9375rem;
  box-shadow: 0 1px 2px rgba(37, 99, 235, 0.3);
}

.btn-primary:hover,
#connectBtn:hover,
#downloadBtn:hover:not(:disabled) {
  background: linear-gradient(180deg, #3b82f6 0%, #2563eb 100%);
  transform: translateY(-1px);
  box-shadow: 0 4px 6px rgba(37, 99, 235, 0.25);
}

.btn-primary:active,
#connectBtn:active,
#downloadBtn:active:not(:disabled) {
  transform: translateY(0);
}

button:disabled {
  background: var(--color-gray-200) !important;
  color: var(--color-gray-400) !important;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

/* Secondary / small button */
.btn-small {
  padding: 0.45rem 0.85rem;
  font-size: 0.8125rem;
  border-radius: var(--radius-default);
  background: var(--color-gray-100);
  color: var(--color-gray-600);
  border: 1px solid var(--color-gray-200);
}

.btn-small:hover {
  background: var(--color-gray-200);
  color: var(--color-gray-700);
}

/* Filter button */
.btn-filter {
  padding: 0.45rem 0.85rem;
  font-size: 0.8125rem;
  border-radius: var(--radius-default);
  background: var(--color-primary);
  color: white;
  border: none;
  box-shadow: 0 1px 2px rgba(37, 99, 235, 0.3);
}

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

/* Clickable document rows */
.doc-row {
  cursor: pointer;
}

.doc-row:hover {
  background: var(--color-primary-subtle);
}

/* Disconnect button */
.btn-disconnect {
  background: transparent;
  color: var(--color-gray-500);
  border: 1px solid var(--color-gray-300);
  padding: 0.45rem 0.85rem;
  font-size: 0.8125rem;
  border-radius: var(--radius-default);
}

.btn-disconnect:hover {
  background: var(--color-error-light);
  color: var(--color-error);
  border-color: var(--color-error);
}

/* --- Filters --- */
.filters {
  display: flex;
  gap: var(--space-md);
  align-items: flex-end;
  margin-bottom: var(--space-lg);
  padding: var(--space-base);
  background: var(--color-gray-50);
  border-radius: var(--radius-default);
  border: 1px solid var(--color-gray-200);
}

.filters .form-group {
  margin-bottom: 0;
  flex: 1;
  min-width: 130px;
}

.filters .form-group label {
  font-size: 0.8rem;
  color: var(--color-gray-500);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-xs);
  font-weight: 600;
}

.filters input[type="date"] {
  padding: 0.5rem 0.625rem;
  font-size: 0.875rem;
}

/* --- Folder Items --- */
.folder-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.875rem 1.125rem;
  border-radius: var(--radius-default);
  margin-bottom: var(--space-sm);
  cursor: pointer;
  background: white;
  border: 1px solid var(--color-gray-200);
  transition: all 0.15s ease;
}

.folder-item:hover {
  background: var(--color-primary-subtle);
  border-color: var(--color-primary-light);
  transform: translateX(2px);
}

.folder-item:active {
  transform: translateX(0);
}

.folder-name {
  font-weight: 500;
  color: var(--color-gray-800);
  font-size: 0.9375rem;
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.folder-name::before {
  content: '';
  display: inline-block;
  width: 20px;
  height: 20px;
  background: var(--color-primary-light);
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%232563eb' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z'%3E%3C/path%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
}

.folder-count {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--color-gray-500);
  background: var(--color-gray-100);
  padding: 0.25rem 0.75rem;
  border-radius: 100px;
  white-space: nowrap;
}

/* --- Table --- */
.table-wrapper {
  overflow-x: auto;
  margin: 0 calc(-1 * var(--space-xl));
  padding: 0 var(--space-xl);
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
}

thead th {
  text-align: left;
  padding: 0.75rem 1rem;
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--color-gray-500);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 2px solid var(--color-gray-200);
  white-space: nowrap;
  position: sticky;
  top: 0;
  background: white;
}

tbody tr {
  transition: background-color 0.1s ease;
}

tbody tr:nth-child(even) {
  background: var(--color-gray-50);
}

tbody tr:hover {
  background: var(--color-primary-subtle);
}

tbody td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--color-gray-100);
  font-size: 0.875rem;
  color: var(--color-gray-600);
  vertical-align: middle;
}

/* Column widths */
thead th:nth-child(1) { width: 44px; }
thead th:nth-child(2) { width: auto; }
thead th:nth-child(3) { width: 120px; }
thead th:nth-child(4) { width: 140px; }
thead th:nth-child(5) { width: 120px; }

/* First column (checkbox) */
tbody td:first-child,
thead th:first-child {
  text-align: center;
  padding-left: var(--space-md);
}

/* Name column — truncate long names */
tbody td:nth-child(2) {
  color: var(--color-gray-800);
  font-weight: 400;
  max-width: 350px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Date, Contact, Type columns */
tbody td:nth-child(3),
tbody td:nth-child(4),
tbody td:nth-child(5) {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Last column */
tbody td:last-child,
thead th:last-child {
  text-align: right;
  padding-right: var(--space-md);
}

/* Selected row */
tbody tr.selected {
  background: var(--color-primary-light);
}

tbody tr.selected td {
  color: var(--color-primary-dark);
}

/* --- Actions bar --- */
.actions {
  margin-top: var(--space-base);
  padding-top: var(--space-base);
  border-top: 1px solid var(--color-gray-200);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.actions .selection-count {
  font-size: 0.8125rem;
  color: var(--color-gray-500);
}

/* --- Status Toast --- */
.status {
  position: fixed;
  bottom: var(--space-xl);
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  padding: 0.875rem 1.5rem;
  border-radius: var(--radius-lg);
  font-size: 0.9375rem;
  font-weight: 500;
  z-index: 1000;
  max-width: 500px;
  width: calc(100% - 2rem);
  text-align: center;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.status:not(.hidden) {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.status.error {
  background: var(--color-error-light);
  color: #991b1b;
  border: 1px solid #fecaca;
}

.status.success {
  background: var(--color-success-light);
  color: #065f46;
  border: 1px solid #a7f3d0;
}

.status.info {
  background: var(--color-primary-subtle);
  color: #1e40af;
  border: 1px solid var(--color-primary-light);
}

/* --- Loading & Empty States --- */
.loading {
  text-align: center;
  padding: var(--space-xl);
  color: var(--color-gray-400);
  font-size: 0.9rem;
}

.loading::before {
  content: '';
  display: block;
  width: 28px;
  height: 28px;
  border: 3px solid var(--color-gray-200);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 0 auto var(--space-md);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.empty {
  text-align: center;
  padding: var(--space-xl);
  color: var(--color-gray-400);
  font-size: 0.9rem;
  font-style: italic;
}

/* --- Utility --- */
.hidden {
  display: none !important;
}

/* --- Login card centering --- */
#auth-section {
  max-width: 440px;
  margin-left: auto;
  margin-right: auto;
}

#auth-section h2 {
  text-align: center;
  margin-bottom: var(--space-lg);
}

#auth-section .login-subtitle {
  text-align: center;
  color: var(--color-gray-500);
  font-size: 0.875rem;
  margin-top: calc(-1 * var(--space-base));
  margin-bottom: var(--space-lg);
}

#connectBtn {
  width: 100%;
  padding: 0.75rem;
  font-size: 1rem;
  margin-top: var(--space-sm);
}

/* --- Build Version --- */
.build-version {
  position: fixed;
  bottom: 0;
  right: 0;
  padding: 3px 10px;
  z-index: 9999;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--color-gray-400);
}

.build-version a {
  color: var(--color-gray-400);
  text-decoration: none;
}

.build-version a:hover {
  color: var(--color-gray-600);
}

/* --- Document Preview Dialog --- */
dialog {
  border: none;
  border-radius: var(--radius-dialog);
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  padding: 0;
  width: 80vw;
  max-width: 1250px;
  height: 85vh;
  max-height: 85vh;
  flex-direction: column;
  overflow: hidden;
}

dialog[open] {
  display: flex;
  margin: auto;
  animation: dialog-enter 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes dialog-enter {
  from {
    opacity: 0;
    transform: scale(0.96);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  animation: backdrop-enter 0.2s ease;
}

@keyframes backdrop-enter {
  from { opacity: 0; }
  to { opacity: 1; }
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-base) var(--space-lg);
  border-bottom: 1px solid var(--color-gray-200);
  background: var(--color-gray-50);
  flex-shrink: 0;
}

.dialog-header h3 {
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--color-gray-900);
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  flex: 1;
}

.dialog-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--color-gray-400);
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-default);
  flex-shrink: 0;
  margin-left: var(--space-md);
}

.dialog-close:hover {
  background: var(--color-gray-200);
  color: var(--color-gray-600);
}

.dialog-footer {
  padding: var(--space-base) var(--space-lg);
  border-top: 1px solid var(--color-gray-200);
  background: var(--color-gray-50);
  display: flex;
  justify-content: flex-end;
  flex-shrink: 0;
}

.dialog-body {
  flex: 1;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.dialog-iframe {
  width: 100%;
  height: 100%;
  border: none;
}

.dialog-image {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.dialog-nopreview {
  text-align: center;
  padding: var(--space-xl);
  color: var(--color-gray-500);
}

.dialog-nopreview p {
  margin-bottom: var(--space-base);
}

.dialog-error {
  text-align: center;
  padding: var(--space-xl);
  color: var(--color-error);
}

/* Admin info dialog */
#adminDialog {
  width: 420px;
  max-width: 90vw;
  height: auto;
  max-height: 80vh;
}

.dialog-body-scroll {
  overflow-y: auto;
  display: block;
  padding: var(--space-lg);
}

.info-group {
  margin-bottom: var(--space-base);
}

.info-group:last-child {
  margin-bottom: 0;
}

.info-group-title {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--color-gray-400);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-sm);
}

.info-group-card {
  background: var(--color-gray-50);
  border-radius: var(--radius-default);
  padding: var(--space-md) var(--space-base);
}

.info-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: var(--space-xs) 0;
}

.info-row + .info-row {
  border-top: 1px solid var(--color-gray-200);
}

.info-label {
  font-size: 0.8125rem;
  color: var(--color-gray-500);
  flex-shrink: 0;
  margin-right: var(--space-base);
}

.info-value {
  font-size: 0.8125rem;
  color: var(--color-gray-900);
  text-align: right;
  word-break: break-word;
}

.info-value.mono {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--color-gray-600);
}

.info-value.active-yes {
  color: var(--color-success);
}

.info-value.active-no {
  color: var(--color-error);
}

.dialog-text {
  width: 100%;
  height: 100%;
  overflow: auto;
  padding: var(--space-lg);
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  line-height: 1.6;
  color: var(--color-gray-800);
  white-space: pre-wrap;
  word-wrap: break-word;
  background: var(--color-gray-50);
  margin: 0;
}

/* --- Responsive --- */
@media (max-width: 640px) {
  .container {
    padding: var(--space-base) var(--space-md);
  }

  .card {
    padding: var(--space-base);
    border-radius: var(--radius-default);
  }

  .table-wrapper {
    margin: 0 calc(-1 * var(--space-base));
    padding: 0 var(--space-base);
  }

  .filters {
    flex-direction: column;
    gap: var(--space-md);
  }

  .filters .form-group {
    min-width: 100%;
  }

  .section-header {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-md);
  }

  .section-header .btn-small,
  .section-header .btn-disconnect {
    align-self: flex-end;
  }

  .folder-item {
    padding: 0.65rem 0.75rem;
  }

  thead th,
  tbody td {
    padding: 0.5rem 0.5rem;
    font-size: 0.8rem;
  }

  /* Hide contact column on mobile */
  thead th:nth-child(4),
  tbody td:nth-child(4) {
    display: none;
  }

  /* Hide type column on very small screens */
  thead th:nth-child(5),
  tbody td:nth-child(5) {
    display: none;
  }
}

@media (max-width: 380px) {
  .app-header h1 {
    font-size: 1rem;
  }

  .app-header .header-subtitle {
    display: none;
  }
}

/* Focus states */
button:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

input:focus-visible {
  outline: none;
}

/* --- Scrollbar (Webkit) --- */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--color-gray-300);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--color-gray-400);
}
