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

:root {
  --bg-primary: #ffffff;
  --bg-secondary: #f8fafc;
  --bg-card: #ffffff;
  --bg-list: #f8fafc;
  --bg-input: #ffffff;
  --bg-header: #64748b;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --text-header: #f1f5f9;
  --border-color: #e2e8f0;
  --border-light: #f1f5f9;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --warning: #f59e0b;
  --success: #22c55e;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.15);
  --radius: 8px;
  --radius-sm: 4px;
}

body.dark {
  --bg-primary: #0f172a;
  --bg-secondary: #334155;
  --bg-card: #1e293b;
  --bg-list: #1e293b;
  --bg-input: #334155;
  --bg-header: #475569;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --text-header: #f1f5f9;
  --border-color: #334155;
  --border-light: #1e293b;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.4);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-secondary);
  color: var(--text-primary);
  line-height: 1.5;
}

/* === Layout === */
.app-layout {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 56px;
  background: var(--bg-header);
  color: var(--text-header);
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.app-logo {
  color: var(--text-header);
  text-decoration: none;
  font-size: 1.25rem;
  font-weight: 700;
}

.user-name {
  font-size: 0.875rem;
  opacity: 0.8;
}

.app-main {
  flex: 1;
  overflow: auto;
}

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-primary);
  cursor: pointer;
  font-size: 0.875rem;
  text-decoration: none;
  transition: background 0.15s;
}
.btn:hover { background: var(--bg-secondary); }
.btn-primary { background: var(--accent); color: white; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { background: var(--danger); color: white; border-color: var(--danger); }
.btn-danger:hover { background: var(--danger-hover); }
.btn-warning { background: var(--warning); color: #000; border-color: var(--warning); }
.btn-sm { padding: 4px 10px; font-size: 0.8rem; }
.btn-block { width: 100%; }
.btn-close {
  background: none; border: none; color: var(--text-secondary);
  font-size: 1.5rem; cursor: pointer; padding: 0 8px;
}
.btn-close:hover { color: var(--text-primary); }
.btn-icon {
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; padding: 4px 8px; font-size: 1.1rem;
}
.btn-icon:hover { color: var(--text-primary); }
.btn-link {
  background: none; border: none; cursor: pointer;
  color: var(--accent); padding: 0; font-size: inherit;
}
.text-danger { color: var(--danger) !important; }

/* === Forms === */
.form-group { margin-bottom: 12px; }
.form-group label {
  display: block; margin-bottom: 4px;
  font-size: 0.8rem; font-weight: 600; color: var(--text-secondary);
}
.form-control {
  width: 100%; padding: 8px 12px;
  border: 1px solid var(--border-color); border-radius: var(--radius-sm);
  background: var(--bg-input); color: var(--text-primary);
  font-size: 1rem;
}
.form-control:focus { outline: none; border-color: var(--accent); }
.form-control-sm { padding: 4px 8px; font-size: 0.8rem; }
textarea.form-control { resize: vertical; font-family: inherit; }
.form-inline { display: flex; gap: 8px; align-items: center; }
.form-inline .form-control { flex: 1; }

select.form-control {
  appearance: auto;
}

/* === Alert === */
.alert { padding: 10px 14px; border-radius: var(--radius-sm); margin-bottom: 12px; font-size: 0.875rem; }
.alert-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
body.dark .alert-error { background: #450a0a; color: #fca5a5; border-color: #7f1d1d; }

/* === Login === */
.login-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; background: var(--bg-secondary);
}
.login-container { width: 100%; max-width: 400px; padding: 20px; }
.login-card {
  background: var(--bg-card); border-radius: var(--radius);
  padding: 32px; box-shadow: var(--shadow-lg); border: 1px solid var(--border-color);
}
.login-card h1 { text-align: center; margin-bottom: 24px; color: var(--text-primary); }
.toggle-text { text-align: center; margin-top: 16px; font-size: 0.875rem; color: var(--text-secondary); }
.toggle-text a { color: var(--accent); text-decoration: none; }

/* === Dashboard === */
.dashboard { padding: 32px; max-width: 1200px; margin: 0 auto; }
.dashboard-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.dashboard-header h1 { font-size: 1.5rem; }
.create-board-form { margin-bottom: 24px; }
.board-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.board-card {
  background: var(--bg-card); border: 1px solid var(--border-color);
  border-radius: var(--radius); padding: 20px; cursor: pointer;
  box-shadow: var(--shadow); transition: box-shadow 0.15s, transform 0.15s;
}
.board-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); }
.board-card h3 { margin-bottom: 8px; }
.board-card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.board-actions { position: relative; }
.board-meta { font-size: 0.8rem; color: var(--text-muted); }
.empty-state { text-align: center; padding: 48px; color: var(--text-muted); }

/* === Board Page === */
.board-page { display: flex; flex-direction: column; height: calc(100vh - 56px); }
.board-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 24px; border-bottom: 1px solid var(--border-color);
  background: var(--bg-primary);
}
.board-header-left, .board-header-right { display: flex; align-items: center; gap: 12px; }
.board-header h1 { font-size: 1.25rem; }
.back-link {
  color: var(--text-secondary); text-decoration: none; font-size: 1.25rem;
}
.back-link:hover { color: var(--text-primary); }

.add-list-inline { padding: 12px 24px; background: var(--bg-secondary); border-bottom: 1px solid var(--border-color); }
.add-list-inline .form-control,
.create-board-form .form-control {
  background: #f1f5f9;
  color: #000000;
  border-color: var(--accent);
}
.add-list-inline .form-control::placeholder,
.create-board-form .form-control::placeholder { color: #475569; }
body.dark .add-list-inline .form-control { background: #475569; }

/* === My Cards Panel === */
.my-cards-panel {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-primary);
  max-height: 240px;
  overflow-y: auto;
}
.my-cards-panel h3 { margin-bottom: 8px; font-size: 1rem; }
.my-card-item {
  padding: 8px 12px; border: 1px solid var(--border-color);
  border-radius: var(--radius-sm); margin-bottom: 6px;
  cursor: pointer; background: var(--bg-card);
}
.my-card-item:hover { background: var(--bg-secondary); }
.card-list-label { font-size: 0.75rem; color: var(--text-muted); margin-left: 8px; }
.card-desc-preview { display: block; font-size: 0.8rem; color: var(--text-secondary); margin-top: 4px; }
.empty-text { color: var(--text-muted); font-size: 0.875rem; }

/* === Board Lists === */
.board-lists {
  display: flex; gap: 12px; padding: 16px 24px;
  overflow-x: auto; flex: 1; align-items: flex-start;
}

.board-list {
  flex: 0 0 300px; min-width: 300px;
  background: var(--bg-list); border: 1px solid var(--border-color);
  border-radius: var(--radius); display: flex; flex-direction: column;
  max-height: calc(100vh - 160px);
}

.board-list.drag-over { border-color: var(--accent); background: rgba(59,130,246,0.05); }
.board-list.dragging { opacity: 0.5; }

.list-header {
  padding: 10px 12px;
  display: flex; align-items: center; justify-content: space-between;
  position: relative;
}
.list-header-content { display: flex; align-items: center; gap: 8px; flex: 1; }
.list-header h3 { font-size: 0.9rem; font-weight: 600; }
.card-count {
  background: var(--bg-secondary); border-radius: 10px;
  padding: 1px 7px; font-size: 0.75rem; color: var(--text-muted);
}
.list-actions { position: relative; }
.dropdown-menu {
  position: absolute; right: 0; top: 100%;
  background: var(--bg-card); border: 1px solid var(--border-color);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-lg);
  z-index: 10; min-width: 140px;
}
.dropdown-menu button {
  display: block; width: 100%; text-align: left;
  padding: 8px 12px; border: none; background: none;
  color: var(--text-primary); cursor: pointer; font-size: 0.8rem;
}
.dropdown-menu button:hover { background: var(--bg-secondary); }

.list-edit-inline { padding: 0 8px 8px; }

.list-cards {
  flex: 1; overflow-y: auto; padding: 0 8px 8px;
  min-height: 20px;
}

.card {
  background: var(--bg-card); border: 1px solid var(--border-color);
  border-radius: var(--radius-sm); padding: 10px 12px;
  margin-bottom: 6px; cursor: pointer; position: relative;
  box-shadow: var(--shadow); transition: box-shadow 0.15s;
}
.card:hover { box-shadow: var(--shadow-lg); }
.card.dragging { opacity: 0.4; }
.card-title { font-size: 0.875rem; font-weight: 500; margin-bottom: 4px; }
.card-desc-indicator { font-size: 0.75rem; color: var(--text-muted); }
.card-tooltip-floating {
  position: fixed; z-index: 2000; width: 280px; max-height: 300px; overflow-y: auto;
  background: #f3f4f6; color: #000; border: 1px solid var(--border-color);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-lg);
}
.card-tooltip-floating .markdown-body { background: none; padding: 10px 12px; color: #000; }
.card-footer { display: flex; gap: 8px; margin-top: 6px; font-size: 0.75rem; color: var(--text-muted); }
.card-assignee {
  color: white;
  padding: 2px 8px; border-radius: 3px; font-size: 0.85rem;
}

.list-footer { padding: 8px; }
.btn-add-card {
  width: 100%; padding: 8px; background: none;
  border: none; color: var(--text-muted); text-align: left;
  cursor: pointer; font-size: 0.875rem; border-radius: var(--radius-sm);
}
.btn-add-card:hover { background: var(--bg-secondary); color: var(--text-primary); }

/* === Modal === */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 20px;
}
.modal-content {
  background: var(--bg-card); border-radius: var(--radius);
  width: 100%; max-width: 680px; max-height: 85vh;
  overflow-y: auto; box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-color);
}
.modal-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: 20px 24px 0;
}
.modal-header h2 { font-size: 1.25rem; flex: 1; }
.modal-header .form-inline { flex: 1; }
.modal-header .form-control { flex: 1; }
.modal-list-label { padding: 0 24px; font-size: 0.8rem; color: var(--text-muted); }

/* === Tabs === */
.modal-tabs {
  display: flex; gap: 0; padding: 12px 24px 0;
  border-bottom: 1px solid var(--border-color);
}
.tab {
  padding: 8px 16px; border: none; background: none;
  color: var(--text-muted); cursor: pointer;
  font-size: 0.875rem; border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab:hover { color: var(--text-primary); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.modal-body { padding: 16px 24px 24px; }

/* === Description === */
.description-display {
  padding: 12px; border: 1px solid var(--border-color);
  border-radius: var(--radius-sm); min-height: 80px;
  cursor: pointer; background: var(--bg-secondary);
}
.description-display:hover { border-color: var(--accent); }
.placeholder-text { color: var(--text-muted); font-style: italic; }
.markdown-preview { margin-top: 12px; }
.markdown-preview label { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 4px; display: block; }
.markdown-body {
  padding: 12px; background: var(--bg-secondary);
  border-radius: var(--radius-sm); font-size: 0.875rem;
  line-height: 1.6; overflow-wrap: break-word;
}
.markdown-body p { margin: 0 0 12px; }
.markdown-body p:last-child { margin-bottom: 0; }
.markdown-body h1, .markdown-body h2, .markdown-body h3 { margin: 12px 0 6px; }
.markdown-body code {
  background: var(--bg-input); padding: 2px 6px; border-radius: 3px;
  font-size: 0.85em;
}
.markdown-body pre {
  background: var(--bg-input); padding: 12px; border-radius: var(--radius-sm);
  overflow-x: auto;
}
.markdown-body pre code { background: none; padding: 0; }
.markdown-body blockquote {
  border-left: 3px solid var(--accent); padding-left: 12px;
  color: var(--text-secondary); margin: 8px 0;
}
.markdown-body img { max-width: 100%; border-radius: var(--radius-sm); }
.markdown-body a { color: var(--accent); }
.markdown-body ul, .markdown-body ol { padding-left: 20px; }
.markdown-body table { border-collapse: collapse; width: 100%; }
.markdown-body th, .markdown-body td {
  border: 1px solid var(--border-color); padding: 6px 10px; text-align: left;
}

.modal-actions { display: flex; gap: 8px; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border-color); }

/* === Comments === */
.comments-list { margin-bottom: 16px; }
.comment {
  padding: 10px 0; border-bottom: 1px solid var(--border-light);
}
.comment-header { display: flex; justify-content: space-between; margin-bottom: 4px; }
.comment-header strong { font-size: 0.875rem; }
.comment-date { font-size: 0.75rem; color: var(--text-muted); }
.comment-content { font-size: 0.875rem; white-space: pre-wrap; }
.add-comment { display: flex; flex-direction: column; gap: 8px; }
.add-comment textarea { flex: 1; }
.add-comment .btn { align-self: flex-end; }

/* === Images === */
.image-upload { margin-bottom: 16px; }
.image-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}
.image-item { text-align: center; }
.image-item img {
  width: 100%; height: 120px; object-fit: cover;
  border-radius: var(--radius-sm); border: 1px solid var(--border-color);
  cursor: pointer;
}
.image-info { margin-top: 4px; font-size: 0.75rem; color: var(--text-muted); display: flex; justify-content: space-between; align-items: center; }

/* === Color Picker === */
.color-picker-sm {
  width: 32px; height: 28px; border: 1px solid var(--border-color);
  border-radius: var(--radius-sm); cursor: pointer; padding: 0;
}

/* === Scrollbar === */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* === Drag Ghost === */
.drag-ghost {
  opacity: 0.8;
}

/* === Admin Page === */
.admin-page {
  padding: 32px;
  max-width: 1000px;
  margin: 0 auto;
}
.admin-page h1 { margin-bottom: 24px; font-size: 1.5rem; }
.admin-section {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 24px;
  box-shadow: var(--shadow);
}
.admin-section h2 { margin-bottom: 20px; font-size: 1.2rem; }
.admin-section h3 { margin: 20px 0 10px; font-size: 1rem; }
.admin-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 16px;
}
.admin-table th, .admin-table td {
  text-align: left;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.875rem;
}
.admin-table th {
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.8rem;
  background: var(--bg-secondary);
}
.admin-table tbody tr:hover { background: var(--bg-secondary); }
.admin-table tbody tr:last-child td { border-bottom: none; }
.row-actions { display: flex; gap: 8px; margin-top: 8px; }

/* Form spacing in admin */
.admin-section .form-inline {
  margin-bottom: 16px;
}
.admin-section .form-group {
  margin-right: 16px;
  margin-bottom: 0;
}
.admin-section .form-group label {
  margin-bottom: 6px;
  font-weight: 500;
}
.admin-section .form-control {
  min-width: 200px;
}

/* Modal in admin */
.admin-page .modal-content {
  max-width: 600px;
  margin: 40px auto;
}
.admin-page .modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-color);
}
.admin-page .modal-body {
  padding: 24px;
}
.admin-page .modal-actions {
  padding: 20px 24px;
  gap: 12px;
  border-top: 1px solid var(--border-color);
}

.header-link {
  color: var(--text-header);
  text-decoration: none;
  font-size: 0.9rem;
  opacity: 0.85;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
}
.header-link:hover { opacity: 1; background: rgba(255,255,255,0.1); }
