/* assets/app.css – Interlink CRM */

@import url('https://fonts.googleapis.com/css2?family=Geist:wght@300;400;500;600&display=swap');

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

:root {
  --bg:          #ffffff;
  --bg-surface:  #f8f8f8;
  --bg-hover:    #f3f4f6;
  --bg-active:   #eff6ff;
  --border:      #e5e7eb;
  --border-soft: #f0f0f0;
  --text:        #111827;
  --text-muted:  #6b7280;
  --text-faint:  #9ca3af;
  --accent:      #3b82f6;
  --accent-bg:   #eff6ff;
  --accent-text: #1d4ed8;
  --status-todo: #3b82f6;
  --status-todo-bg: #eff6ff;
  --status-todo-text: #1e40af;
  --status-inprogress: #f59e0b;
  --status-inprogress-bg: #fffbeb;
  --status-inprogress-text: #92400e;
  --status-done: #10b981;
  --status-done-bg: #ecfdf5;
  --status-done-text: #065f46;
  --status-cancelled: #6b7280;
  --status-cancelled-bg: #f3f4f6;
  --status-cancelled-text: #374151;
  --sidebar-w:   176px;
  --topbar-h:    48px;
  --detail-w:    320px;
  --font: 'Geist', -apple-system, BlinkMacSystemFont, sans-serif;
  --radius: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
}

html, body { height: 100%; font-family: var(--font); font-size: 13px; color: var(--text); background: var(--bg); }

/* ── Layout ─────────────────────────────────────────────── */
#app { display: flex; height: 100vh; overflow: hidden; }

/* ── Sidebar ────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 8px 0;
  background: var(--bg);
}

.sidebar-workspace {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px 12px;
  cursor: pointer;
  user-select: none;
}
.ws-logo {
  width: 22px; height: 22px;
  background: #6366f1;
  border-radius: 5px;
  display: flex; align-items: center; justify-content: center;
  color: white; font-size: 11px; font-weight: 600;
}
.ws-name { font-size: 13px; font-weight: 500; }
.ws-chevron { margin-left: auto; color: var(--text-muted); font-size: 10px; }

.sidebar-action {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius);
  margin: 0 6px;
  font-size: 12px;
  transition: background .1s;
}
.sidebar-action:hover { background: var(--bg-hover); color: var(--text); }

.sidebar-section {
  padding: 16px 12px 4px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: .06em;
}

.sidebar-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px;
  margin: 1px 6px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
  transition: background .1s, color .1s;
  user-select: none;
}
.sidebar-item:hover         { background: var(--bg-hover); color: var(--text); }
.sidebar-item.active        { background: var(--bg-hover); color: var(--text); font-weight: 500; }
.sidebar-item .item-icon    { width: 16px; font-size: 14px; flex-shrink: 0; }
.sidebar-item .item-count   { margin-left: auto; font-size: 11px; color: var(--text-faint); }
.sidebar-item .item-chevron { margin-left: auto; font-size: 10px; color: var(--text-faint); }

/* ── Main area ──────────────────────────────────────────── */
#main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

/* ── Top bar ────────────────────────────────────────────── */
#topbar {
  height: var(--topbar-h);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 8px;
  flex-shrink: 0;
}
.topbar-title { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 500; }
.topbar-title .module-icon { font-size: 15px; }
.topbar-spacer { flex: 1; }
.topbar-btn {
  display: flex; align-items: center; gap: 5px;
  padding: 5px 10px; border-radius: var(--radius);
  border: none; background: transparent;
  font-size: 12px; font-family: var(--font);
  color: var(--text-muted); cursor: pointer;
  transition: background .1s;
}
.topbar-btn:hover { background: var(--bg-hover); color: var(--text); }
.topbar-btn.primary {
  background: var(--text); color: white;
  font-weight: 500;
}
.topbar-btn.primary:hover { background: #374151; }

/* ── View bar ───────────────────────────────────────────── */
#viewbar {
  height: 40px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 4px;
  flex-shrink: 0;
}
.view-tab {
  display: flex; align-items: center; gap: 5px;
  padding: 5px 10px; border-radius: var(--radius);
  font-size: 12px; color: var(--text-muted);
  cursor: pointer; border: none; background: transparent;
  font-family: var(--font);
  transition: background .1s;
}
.view-tab:hover  { background: var(--bg-hover); color: var(--text); }
.view-tab.active { background: var(--bg-hover); color: var(--text); font-weight: 500; }
.view-count      { font-size: 11px; color: var(--text-faint); }
.view-spacer     { flex: 1; }
.view-action {
  display: flex; align-items: center; gap: 4px;
  padding: 4px 9px; border-radius: var(--radius);
  font-size: 12px; color: var(--text-muted);
  cursor: pointer; border: none; background: transparent;
  font-family: var(--font);
  transition: background .1s;
}
.view-action:hover { background: var(--bg-hover); color: var(--text); }

/* ── Table ──────────────────────────────────────────────── */
#table-wrap {
  flex: 1;
  overflow: auto;
}

.task-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.task-table th {
  position: sticky; top: 0;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 0 12px;
  height: 36px;
  text-align: left;
  font-weight: 500;
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  user-select: none;
  z-index: 1;
}
.task-table th.col-cb  { width: 32px; padding: 0 8px; }
.task-table th.col-title { min-width: 240px; }
.task-table th .th-inner { display: flex; align-items: center; gap: 4px; }

.task-table tr.task-row {
  border-bottom: 1px solid var(--border-soft);
  cursor: pointer;
  transition: background .1s;
}
.task-table tr.task-row:hover { background: var(--bg-hover); }
.task-table tr.task-row.selected { background: var(--bg-active); }

.task-table td { padding: 0 12px; height: 38px; vertical-align: middle; white-space: nowrap; }
.task-table td.col-cb { padding: 0 8px; }

/* Checkbox */
.cb { width: 14px; height: 14px; border: 1.5px solid var(--border); border-radius: 3px; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: border-color .15s, background .15s; flex-shrink: 0; }
.cb:hover { border-color: var(--accent); }
.cb.checked { background: var(--accent); border-color: var(--accent); }
.cb.checked::after { content: '✓'; color: white; font-size: 9px; }

/* Title cell */
.title-cell { display: flex; align-items: center; gap: 8px; }
.task-icon  { font-size: 13px; color: var(--accent); flex-shrink: 0; }
.task-label { font-size: 11px; color: var(--text-muted); font-weight: 500; flex-shrink: 0; }
.task-title-text { color: var(--text); font-weight: 400; }

/* Status badge */
.status-badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 8px; border-radius: 4px;
  font-size: 12px; font-weight: 500;
}
.status-todo        { background: var(--status-todo-bg);         color: var(--status-todo-text); }
.status-in_progress { background: var(--status-inprogress-bg);   color: var(--status-inprogress-text); }
.status-done        { background: var(--status-done-bg);          color: var(--status-done-text); }
.status-cancelled   { background: var(--status-cancelled-bg);     color: var(--status-cancelled-text); }
.status-dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.dot-todo       { background: var(--status-todo); }
.dot-in_progress{ background: var(--status-inprogress); }
.dot-done       { background: var(--status-done); }
.dot-cancelled  { background: var(--status-cancelled); }

/* Avatar */
.avatar {
  width: 20px; height: 20px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 9px; font-weight: 600; color: white; flex-shrink: 0;
}
.user-cell { display: flex; align-items: center; gap: 6px; color: var(--text); }
.user-cell .user-name { max-width: 140px; overflow: hidden; text-overflow: ellipsis; }

/* Date cell */
.date-cell { color: var(--text-muted); font-size: 12px; }
.date-cell.overdue { color: #ef4444; }

/* Add new row */
.add-row td { color: var(--text-muted); font-size: 12px; cursor: pointer; }
.add-row td:hover { color: var(--accent); }

/* Calculate row */
.calc-row td {
  height: 34px; color: var(--text-faint); font-size: 12px; cursor: pointer;
  border-top: 1px solid var(--border-soft);
}
.calc-row td:hover { color: var(--text-muted); }
.calc-inner { display: flex; align-items: center; gap: 4px; }

/* ── Detail Panel ───────────────────────────────────────── */
#detail {
  width: var(--detail-w);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
  background: var(--bg);
  transition: width .2s, opacity .2s;
}
#detail.hidden { width: 0; opacity: 0; overflow: hidden; }

.detail-header {
  display: flex; align-items: center; gap: 8px;
  padding: 0 14px;
  height: var(--topbar-h);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.detail-close {
  width: 24px; height: 24px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 4px; cursor: pointer; color: var(--text-muted);
  transition: background .1s; font-size: 14px;
}
.detail-close:hover { background: var(--bg-hover); color: var(--text); }
.detail-task-id { font-size: 13px; font-weight: 500; color: var(--accent); }
.detail-created  { font-size: 12px; color: var(--text-muted); flex: 1; }
.detail-open-btn {
  display: flex; align-items: center; gap: 4px;
  padding: 4px 8px; border-radius: var(--radius);
  background: var(--accent); color: white;
  font-size: 11px; font-weight: 500; cursor: pointer; border: none;
  font-family: var(--font);
}

/* Detail tabs */
.detail-tabs {
  display: flex; gap: 0;
  border-bottom: 1px solid var(--border);
  padding: 0 14px;
  flex-shrink: 0;
}
.detail-tab {
  display: flex; align-items: center; gap: 5px;
  padding: 10px 10px 9px;
  font-size: 12px; font-weight: 500; color: var(--text-muted);
  cursor: pointer; border: none; background: transparent;
  font-family: var(--font);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color .1s;
}
.detail-tab:hover  { color: var(--text); }
.detail-tab.active { color: var(--text); border-bottom-color: var(--text); }

/* Detail body */
.detail-body { flex: 1; overflow-y: auto; padding: 14px; }

/* Fields section */
.fields-section { margin-bottom: 16px; }
.fields-title {
  font-size: 11px; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .06em;
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 4px; cursor: pointer;
}
.fields-grid { display: flex; flex-direction: column; gap: 0; }
.field-row {
  display: flex; align-items: center;
  padding: 5px 0; gap: 8px;
  border-radius: var(--radius);
  transition: background .1s;
  cursor: pointer;
}
.field-row:hover { background: var(--bg-hover); margin: 0 -6px; padding: 5px 6px; }
.field-label { width: 90px; font-size: 12px; color: var(--text-muted); flex-shrink: 0; display: flex; align-items: center; gap: 5px; }
.field-label svg, .field-label .fi { font-size: 12px; }
.field-value { font-size: 12px; color: var(--text); flex: 1; }
.field-value.empty { color: var(--text-faint); }

/* Detail separator */
.detail-sep { margin: 8px -14px; border: none; border-top: 1px solid var(--border); }

/* Task body editor area */
.task-body-section { margin-top: 8px; }
.task-body-label { font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 8px; }
.task-body-editor {
  min-height: 120px;
  font-size: 13px;
  color: var(--text);
  outline: none;
  line-height: 1.6;
  caret-color: var(--accent);
}
.task-body-editor:empty::before {
  content: attr(data-placeholder);
  color: var(--text-faint);
  pointer-events: none;
}

/* Timeline */
.timeline-item {
  display: flex; gap: 10px; padding: 8px 0;
  border-bottom: 1px solid var(--border-soft);
  font-size: 12px;
}
.timeline-item:last-child { border-bottom: none; }
.timeline-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--border); margin-top: 5px; flex-shrink: 0; }
.timeline-text { color: var(--text-muted); flex: 1; line-height: 1.5; }
.timeline-time { color: var(--text-faint); font-size: 11px; flex-shrink: 0; }

/* ── Modal ──────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.25);
  display: flex; align-items: flex-start; justify-content: center;
  padding-top: 80px;
  z-index: 100;
  animation: fadeIn .1s ease;
}
.modal {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 480px;
  box-shadow: 0 20px 60px rgba(0,0,0,.15);
  overflow: hidden;
  animation: slideIn .15s ease;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 14px; font-weight: 600; }
.modal-close { cursor: pointer; color: var(--text-muted); font-size: 16px; width: 24px; height: 24px; display: flex; align-items: center; justify-content: center; border-radius: 4px; }
.modal-close:hover { background: var(--bg-hover); color: var(--text); }
.modal-body { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.modal-footer { padding: 12px 16px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }

/* Form fields */
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-label { font-size: 12px; font-weight: 500; color: var(--text-muted); }
.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  outline: none;
  transition: border-color .15s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus { border-color: var(--accent); }
.form-textarea { min-height: 80px; resize: vertical; }
.btn {
  padding: 7px 14px; border-radius: var(--radius);
  font-size: 13px; font-family: var(--font);
  cursor: pointer; border: none; font-weight: 500;
  transition: background .1s;
}
.btn-primary { background: var(--text); color: white; }
.btn-primary:hover { background: #374151; }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); }
.btn-danger { background: #fee2e2; color: #b91c1c; }
.btn-danger:hover { background: #fecaca; }

/* Toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: white;
  padding: 8px 16px; border-radius: 8px;
  font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow);
  z-index: 200; animation: fadeIn .2s ease;
}
.toast.error { background: #ef4444; }

/* Loading */
.loading { display: flex; align-items: center; justify-content: center; height: 100px; color: var(--text-faint); font-size: 13px; }
.spinner { width: 16px; height: 16px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .6s linear infinite; margin-right: 8px; }

/* Empty state */
.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 60px 20px; color: var(--text-muted); gap: 8px; }
.empty-icon { font-size: 32px; opacity: .4; }
.empty-text { font-size: 14px; font-weight: 500; }
.empty-sub  { font-size: 12px; color: var(--text-faint); }

/* Context menu */
.ctx-menu {
  position: fixed; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  min-width: 160px; z-index: 150; overflow: hidden;
  animation: fadeIn .1s ease;
}
.ctx-item {
  padding: 7px 14px; font-size: 13px; cursor: pointer; color: var(--text);
  display: flex; align-items: center; gap: 8px;
  transition: background .1s;
}
.ctx-item:hover { background: var(--bg-hover); }
.ctx-item.danger { color: #ef4444; }
.ctx-item.danger:hover { background: #fee2e2; }
.ctx-sep { border: none; border-top: 1px solid var(--border); margin: 4px 0; }

@keyframes fadeIn  { from { opacity:0; } to { opacity:1; } }
@keyframes slideIn { from { opacity:0; transform: translateY(-8px); } to { opacity:1; transform:none; } }
@keyframes spin    { to { transform: rotate(360deg); } }

/* Scrollbar */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #d1d5db; }

/* Search bar */
.search-wrap { position: relative; }
.search-input {
  padding: 5px 10px 5px 30px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px; font-family: var(--font);
  color: var(--text); background: var(--bg-surface);
  outline: none; width: 200px;
  transition: border-color .15s, width .2s;
}
.search-input:focus { border-color: var(--accent); width: 240px; }
.search-icon { position: absolute; left: 8px; top: 50%; transform: translateY(-50%); color: var(--text-faint); font-size: 12px; }
