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

:root {
  --primary: #0f8f67;
  --primary-dark: #0d8060;
  --bg-dark: #0f172a;
  --bg-card: #1e293b;
  --bg-hover: #334155;
  --border: #475569;
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --success: #10b981;
  --warning: #f59e0b;
  --error: #ef4444;
  --radius: 8px;
}

body {
  font-family: 'Noto Sans Thai', sans-serif;
  background: var(--bg-dark);
  color: var(--text);
  min-height: 100vh;
}

.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Header */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 24px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--primary);
}

.logo i {
  font-size: 1.5rem;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.api-key-input {
  display: flex;
  gap: 4px;
}

.api-key-input input {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-dark);
  color: var(--text);
  width: 200px;
  font-size: 0.875rem;
}

.api-key-input button {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-dark);
  color: var(--text);
  cursor: pointer;
  transition: all 0.2s;
}

.api-key-input button:hover {
  background: var(--bg-hover);
  color: var(--primary);
}

.stats-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--bg-dark);
  border-radius: var(--radius);
  font-size: 0.875rem;
  color: var(--text-muted);
}

/* Toolbar */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}

.filter-group {
  display: flex;
  gap: 12px;
  align-items: center;
}

.filter-group select,
.filter-group input {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-dark);
  color: var(--text);
  font-size: 0.875rem;
}

.filter-group input {
  width: 150px;
}

.filter-group select {
  min-width: 120px;
}

.btn-icon {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-dark);
  color: var(--text);
  cursor: pointer;
  transition: all 0.2s;
}

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

.btn {
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s;
}

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

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

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

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

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

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

/* Main */
.main {
  flex: 1;
  padding: 24px;
}

/* File Table */
.file-table-container {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
}

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

.file-table th,
.file-table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.file-table th {
  background: var(--bg-dark);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--text-muted);
}

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

.col-preview { width: 60px; }
.col-name { min-width: 200px; }
.col-app { width: 80px; }
.col-user { width: 120px; }
.col-type { width: 80px; }
.col-size { width: 100px; }
.col-date { width: 140px; }
.col-actions { width: 100px; }

.file-icon {
  width: 40px;
  height: 40px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
}

.file-icon.image { background: #8b5cf6; }
.file-icon.video { background: #ec4899; }
.file-icon.audio { background: #f59e0b; }
.file-icon.pdf { background: #ef4444; }
.file-icon.default { background: #64748b; }

.file-name {
  font-weight: 500;
  word-break: break-all;
}

.file-name small {
  display: block;
  color: var(--text-muted);
  font-size: 0.75rem;
  margin-top: 2px;
}

.app-badge {
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
}

.app-badge.tts { background: #8b5cf6; color: white; }
.app-badge.green { background: #10b981; color: white; }
.app-badge.cutdee { background: #3b82f6; color: white; }

.type-badge {
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  background: var(--bg-dark);
  color: var(--text-muted);
}

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

.actions-group button {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: all 0.2s;
}

.actions-group button:hover {
  background: var(--bg-dark);
  color: var(--primary);
}

.actions-group button.delete:hover {
  color: var(--error);
}

.empty-row td {
  padding: 60px 20px;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
}

.empty-state i {
  font-size: 3rem;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-state p {
  font-size: 1.125rem;
  margin-bottom: 8px;
}

/* Pagination */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  margin-top: 20px;
}

.pagination button {
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--text);
  cursor: pointer;
  transition: all 0.2s;
}

.pagination button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.pagination button:not(:disabled):hover {
  background: var(--bg-hover);
  color: var(--primary);
}

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal.active {
  display: flex;
}

.modal-content {
  background: var(--bg-card);
  border-radius: var(--radius);
  width: 90%;
  max-width: 500px;
  max-height: 90vh;
  overflow: auto;
}

.modal-content.modal-large {
  max-width: 800px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.125rem;
}

.close-btn {
  padding: 8px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 4px;
  transition: all 0.2s;
}

.close-btn:hover {
  background: var(--bg-hover);
  color: var(--error);
}

.modal-body {
  padding: 20px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

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

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-dark);
  color: var(--text);
  font-size: 0.875rem;
}

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

/* File Input */
.file-input-wrapper {
  position: relative;
}

.file-input-wrapper input[type="file"] {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.file-input-preview {
  padding: 40px 20px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  text-align: center;
  color: var(--text-muted);
  transition: all 0.2s;
}

.file-input-preview i {
  font-size: 2.5rem;
  margin-bottom: 10px;
  color: var(--primary);
}

.file-input-preview.dragover {
  border-color: var(--primary);
  background: rgba(15, 143, 103, 0.1);
}

.file-list {
  margin-top: 12px;
  text-align: left;
}

.file-list .file-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: var(--bg-dark);
  border-radius: 4px;
  margin-bottom: 6px;
  font-size: 0.875rem;
}

.file-list .file-item i {
  margin-right: 8px;
  color: var(--primary);
}

/* Progress */
.upload-progress {
  margin-top: 16px;
}

.progress-bar {
  height: 8px;
  background: var(--bg-dark);
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  transition: width 0.3s;
  width: 0%;
}

/* Preview */
.preview-image {
  max-width: 100%;
  max-height: 60vh;
  object-fit: contain;
}

.preview-video {
  max-width: 100%;
  max-height: 60vh;
}

.preview-audio {
  width: 100%;
  margin-top: 20px;
}

.preview-text {
  background: var(--bg-dark);
  padding: 16px;
  border-radius: var(--radius);
  max-height: 60vh;
  overflow: auto;
  white-space: pre-wrap;
  font-size: 0.875rem;
}

.preview-unsupported {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.preview-unsupported i {
  font-size: 4rem;
  margin-bottom: 16px;
  opacity: 0.5;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  gap: 10px;
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.3s;
  z-index: 2000;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.toast.success i { color: var(--success); }
.toast.error i { color: var(--error); }
.toast.warning i { color: var(--warning); }

/* Responsive */
@media (max-width: 768px) {
  .header {
    flex-direction: column;
    gap: 12px;
  }

  .toolbar {
    flex-direction: column;
    gap: 12px;
  }

  .filter-group {
    flex-wrap: wrap;
  }

  .file-table {
    font-size: 0.75rem;
  }

  .col-app,
  .col-user,
  .col-type {
    display: none;
  }

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