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

:root {
  --bg: #0f1117;
  --bg-surface: #1a1d27;
  --bg-elevated: #222633;
  --border: #2d3348;
  --text: #e1e4eb;
  --text-muted: #7b8298;
  --accent: #4f8ff7;
  --accent-hover: #3a7ae8;
  --danger: #e5484d;
  --danger-hover: #d13438;
  --success: #30a46c;
  --radius: 8px;
  --radius-lg: 12px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

/* ===== Navbar ===== */
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 56px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.nav-brand {
  font-weight: 700;
  font-size: 16px;
  color: var(--text);
  white-space: nowrap;
}
.nav-brand:hover {
  color: var(--accent);
  text-decoration: none;
}

.breadcrumb-sep {
  color: var(--text-muted);
  font-size: 14px;
}

.breadcrumb-link {
  font-size: 14px;
  color: var(--text-muted);
}
.breadcrumb-link:hover {
  color: var(--accent);
}

.breadcrumb-current {
  font-size: 14px;
  color: var(--text);
  font-weight: 500;
}

.nav-right {
  flex-shrink: 0;
}

.logout-form {
  display: inline;
}

/* ===== Container ===== */
.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px;
}

/* ===== Page Header ===== */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
}

.page-header h1 {
  font-size: 24px;
  font-weight: 600;
}

.header-actions {
  display: flex;
  gap: 8px;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
  line-height: 1.4;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  text-decoration: none;
}

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

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: transparent;
}
.btn-ghost:hover {
  color: var(--text);
  background: var(--bg-elevated);
  text-decoration: none;
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: var(--danger);
}
.btn-danger:hover {
  background: var(--danger);
  color: #fff;
}

.btn-small {
  padding: 4px 10px;
  font-size: 12px;
}

.btn-full {
  width: 100%;
}

/* ===== Flash Messages ===== */
.flash {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 20px;
  font-size: 14px;
  border: 1px solid;
}

.flash-error {
  background: rgba(229, 72, 77, 0.1);
  border-color: rgba(229, 72, 77, 0.3);
  color: #f87171;
}

.flash-success {
  background: rgba(48, 164, 108, 0.1);
  border-color: rgba(48, 164, 108, 0.3);
  color: #4ade80;
}

/* ===== Forms ===== */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="email"] {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.15s ease;
}

.form-group input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 143, 247, 0.15);
}

.form-group input[type="file"] {
  font-size: 14px;
  color: var(--text-muted);
}
.form-group input[type="file"]::file-selector-button {
  padding: 8px 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  margin-right: 12px;
  font-family: inherit;
}
.form-group input[type="file"]::file-selector-button:hover {
  background: var(--border);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

/* ===== Login ===== */
.login-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 32px;
}

.login-title {
  font-size: 24px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 4px;
}

.login-subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 28px;
}

.login-form .form-group {
  margin-bottom: 20px;
}

.login-form .btn {
  margin-top: 8px;
}

/* ===== Search ===== */
.search-bar {
  display: flex;
  gap: 8px;
}

.search-input {
  flex: 1;
  padding: 10px 14px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}

.search-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 143, 247, 0.15);
}

.search-input::placeholder {
  color: var(--text-muted);
}

/* ===== Card Grid ===== */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}

.card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 20px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  transition: all 0.15s ease;
  color: inherit;
}
.card:hover {
  border-color: var(--accent);
  background: var(--bg-elevated);
  text-decoration: none;
  transform: translateY(-1px);
}

.card-icon {
  font-size: 28px;
  flex-shrink: 0;
}

.card-body {
  min-width: 0;
}

.card-title {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-meta {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ===== Upload Panel ===== */
.upload-panel {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 24px;
}

.hidden {
  display: none !important;
}

/* ===== File Table ===== */
.file-table-wrap {
  overflow-x: auto;
}

.file-table {
  width: 100%;
  border-collapse: collapse;
}

.file-table thead th {
  text-align: left;
  padding: 10px 14px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
}

.file-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.1s ease;
}
.file-table tbody tr:hover {
  background: var(--bg-elevated);
}
.file-table tbody tr:last-child {
  border-bottom: none;
}

.file-table td {
  padding: 12px 14px;
  font-size: 14px;
}

.file-name {
  font-weight: 500;
}
.file-name a {
  color: var(--text);
}
.file-name a:hover {
  color: var(--accent);
}

.file-size {
  color: var(--text-muted);
  white-space: nowrap;
}

.file-date {
  color: var(--text-muted);
  white-space: nowrap;
}

.file-actions {
  text-align: right;
  white-space: nowrap;
}

.file-actions form {
  display: inline;
}

/* ===== Profile Split Layout ===== */
.profile-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 24px;
  align-items: start;
}

.panel-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}

.panel-empty {
  font-size: 13px;
  color: var(--text-muted);
  padding: 8px 0;
}

/* Sidebar (subfolders) */
.profile-sidebar {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  color: var(--text);
  transition: background 0.1s ease;
  margin-bottom: 2px;
}
.sidebar-item:hover {
  background: var(--bg-elevated);
  text-decoration: none;
}

.sidebar-icon {
  font-size: 18px;
  flex-shrink: 0;
}

.sidebar-name {
  flex: 1;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-count {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg);
  padding: 2px 8px;
  border-radius: 10px;
  flex-shrink: 0;
}

.sidebar-source {
  font-size: 10px;
  color: var(--accent);
  background: rgba(79, 143, 247, 0.1);
  padding: 2px 6px;
  border-radius: 6px;
  flex-shrink: 0;
  font-family: monospace;
}

/* Fields panel */
.profile-fields {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.fields-list {
  margin-bottom: 16px;
}

.field-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.field-row:last-child {
  border-bottom: none;
}

.field-edit-form {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.field-delete-form {
  flex-shrink: 0;
}

.field-key {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  min-width: 100px;
  max-width: 140px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 0;
}

.field-value-wrap {
  flex: 1;
  min-width: 0;
}

.field-input {
  width: 100%;
  padding: 6px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
}
.field-input:focus {
  outline: none;
  border-color: var(--accent);
}

.field-actions {
  flex-shrink: 0;
}

.add-field-form {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.add-field-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.add-field-row .field-input {
  flex: 1;
}

.card-source {
  font-size: 11px;
  color: var(--accent);
  font-family: monospace;
  margin-top: 4px;
}

/* Dashboard field preview */
.card-fields-preview {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ===== Notification Banner ===== */
.notification-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: rgba(79, 143, 247, 0.1);
  border: 1px solid rgba(79, 143, 247, 0.25);
  border-radius: var(--radius);
  margin-bottom: 20px;
  font-size: 14px;
  color: var(--accent);
}

.notification-icon {
  font-size: 18px;
  flex-shrink: 0;
}

/* ===== Search + Sort Bar ===== */
.search-sort-bar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 24px;
}

.sort-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
  width: fit-content;
}

.sort-tab {
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  border-radius: 6px;
  transition: all 0.15s ease;
}
.sort-tab:hover {
  color: var(--text);
  background: var(--bg-elevated);
  text-decoration: none;
}
.sort-tab.active {
  color: #fff;
  background: var(--accent);
}
.sort-tab.active:hover {
  background: var(--accent-hover);
  text-decoration: none;
}

/* ===== Card Badge ===== */
.card {
  position: relative;
}

.card-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 2px 8px;
  border-radius: 10px;
  text-transform: uppercase;
}

.badge-new {
  background: rgba(48, 164, 108, 0.15);
  color: var(--success);
  border: 1px solid rgba(48, 164, 108, 0.3);
}

.badge-updated {
  background: rgba(79, 143, 247, 0.15);
  color: var(--accent);
  border: 1px solid rgba(79, 143, 247, 0.3);
}

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
  font-size: 15px;
}

/* ===== Error Page ===== */
.error-page {
  text-align: center;
  padding: 80px 20px;
}
.error-page h1 {
  font-size: 48px;
  font-weight: 700;
  margin-bottom: 8px;
}
.error-page p {
  color: var(--text-muted);
  font-size: 16px;
  margin-bottom: 24px;
}

/* ===== Responsive ===== */
@media (max-width: 640px) {
  .container {
    padding: 16px;
  }

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

  .form-row {
    grid-template-columns: 1fr;
  }

  .card-grid {
    grid-template-columns: 1fr;
  }

  .search-bar {
    flex-direction: column;
  }

  .sort-tabs {
    width: 100%;
  }

  .sort-tab {
    flex: 1;
    text-align: center;
  }

  .profile-layout {
    grid-template-columns: 1fr;
  }

  .navbar {
    padding: 0 16px;
  }

  .nav-left {
    overflow: hidden;
  }
}
