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

:root {
  --bg: #F6F8FB;
  --surface: #FFFFFF;
  --surface-hover: #F7FAFD;
  --surface-alt: #F1F5F9;
  --border: #E4EAF0;
  --border-strong: #CBD5DC;
  --text: #1F2A31;
  --text-muted: #64727A;
  --text-subtle: #94A0A8;
  --accent: #1988F0;
  --accent-hover: #0F6DC7;
  --accent-soft: rgba(25, 136, 240, 0.10);
  --secondary: #20BCD4;
  --highlight: #C9D935;

  --urgent: #DC2626;
  --urgent-bg: #FEF2F2;
  --high: #EA580C;
  --high-bg: #FFF7ED;
  --normal: #64727A;
  --normal-bg: #F1F5F9;
  --low: #94A0A8;
  --low-bg: #F8FAFC;

  --status-todo: #64727A;
  --status-todo-bg: #F1F5F9;
  --status-progress: #1988F0;
  --status-progress-bg: #EFF6FF;
  --status-hold: #A16207;
  --status-hold-bg: #FEFCE8;
  --status-done: #16A34A;
  --status-done-bg: #F0FDF4;
  --status-cancel: #94A0A8;
  --status-cancel-bg: #F8FAFC;

  --radius: 6px;
  --radius-lg: 8px;
  --shadow-sm: 0 1px 2px rgba(15, 30, 50, 0.04);
  --shadow-md: 0 2px 4px rgba(15, 30, 50, 0.06), 0 1px 2px rgba(15, 30, 50, 0.04);
  --shadow-lg: 0 12px 40px rgba(15, 30, 50, 0.18);
}

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#app-shell {
  min-height: 100vh;
  background: var(--surface);
  display: flex;
  flex-direction: column;
}

/* ─── Header ─────────────────────────────────────────── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  gap: 16px;
}

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

.brand-logo {
  height: 32px;
  width: auto;
  display: block;
}

h1 {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
  margin: 0;
}

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

/* ─── Status tabs ─────────────────────────────────────── */
.status-tabs {
  display: flex;
  gap: 4px;
  padding: 0 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.status-tabs::-webkit-scrollbar { display: none; }

.status-tab {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 14px 4px;
  margin: 0 12px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  transition: color 0.15s;
  margin-bottom: -1px;
}
.status-tab:first-child { margin-left: 0; }

.status-tab:hover { color: var(--text); }

.status-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

.tab-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface-alt);
  border-radius: 10px;
  padding: 0 7px;
  min-width: 22px;
  height: 18px;
  line-height: 1;
}

.status-tab.active .tab-count {
  background: var(--accent-soft);
  color: var(--accent);
}

/* ─── Filter bar ──────────────────────────────────────── */
.filter-bar {
  display: flex;
  gap: 8px;
  padding: 12px 28px;
  background: #F5F9FC;
  border-bottom: 1px solid var(--border);
  align-items: center;
  flex-wrap: wrap;
}

.filter-select {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  height: 32px;
  border-radius: var(--radius);
  font-size: 12.5px;
  outline: none;
  min-width: 130px;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%2394A0A8' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

.filter-select[type="date"] {
  padding-right: 10px;
  background-image: none;
}

.filter-select:hover { border-color: var(--border-strong); }
.filter-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.filter-search {
  flex: 1;
  min-width: 220px;
  max-width: 340px;
}

.filter-search input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px 6px 32px;
  height: 32px;
  border-radius: var(--radius);
  font-size: 12.5px;
  outline: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2394A0A8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 10px center;
}

.filter-search input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.btn-link {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 500;
  padding: 6px 8px;
  border-radius: var(--radius);
}
.btn-link:hover { background: var(--accent-soft); }

/* ─── Buttons ─────────────────────────────────────────── */
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: 1px solid var(--accent);
  padding: 0 14px;
  height: 34px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 1px 2px rgba(25, 136, 240, 0.16);
}
.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  box-shadow: 0 2px 6px rgba(25, 136, 240, 0.24);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0 12px;
  height: 34px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  box-shadow: var(--shadow-sm);
}
.btn-secondary:hover {
  border-color: var(--border-strong);
  background: var(--surface-hover);
}
.btn-secondary svg { display: block; opacity: 0.85; }

.btn-signout {
  padding: 0 10px;
  color: var(--text-muted);
}
.btn-signout:hover { color: var(--urgent); }

/* ─── Main / table ───────────────────────────────────── */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.table-wrap {
  overflow-x: auto;
  overflow-y: visible;
  background: var(--surface);
  flex: 1;
}

.task-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
  min-width: 1400px;
}

.task-table thead {
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 2;
}

.task-table th {
  text-align: left;
  padding: 11px 14px;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 11.5px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  vertical-align: middle;
}

.task-table th[data-col-key] {
  cursor: grab;
  user-select: none;
  position: relative;
}
.task-table th[data-col-key]:active { cursor: grabbing; }

.th-grip {
  display: inline-block;
  color: var(--text-subtle);
  opacity: 0;
  margin-right: 4px;
  transition: opacity 0.15s;
  font-size: 10px;
  letter-spacing: -2px;
  vertical-align: middle;
  cursor: grab;
}
.task-table th[data-col-key]:hover .th-grip { opacity: 0.6; }

.task-table th.dragging {
  opacity: 0.4;
  background: var(--accent-soft);
}

.task-table th.drop-before {
  box-shadow: inset 3px 0 0 0 var(--accent);
}
.task-table th.drop-after {
  box-shadow: inset -3px 0 0 0 var(--accent);
}

.task-table th.sortable {
  cursor: pointer;
  user-select: none;
  position: relative;
}

.task-table th.sortable::after {
  content: '↕';
  display: inline-block;
  margin-left: 6px;
  font-size: 10px;
  color: var(--text-subtle);
  opacity: 0;
  transition: opacity 0.15s;
}
.task-table th.sortable:hover { color: var(--text); }
.task-table th.sortable:hover::after { opacity: 0.8; }
.task-table th.sort-asc::after { content: '↑'; opacity: 1; color: var(--accent); }
.task-table th.sort-desc::after { content: '↓'; opacity: 1; color: var(--accent); }

.task-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.task-table tbody tr {
  cursor: pointer;
  transition: background 0.08s ease;
}
.task-table tbody tr:hover { background: var(--surface-hover); }

/* Column widths — tuned to prevent wrapping */
.col-priority { width: 96px; }
.col-due      { width: 96px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.col-id       { width: 68px; font-weight: 500; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.col-type     { width: 150px; }
.col-customer { width: 180px; max-width: 180px; }
.col-job      { width: 90px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.col-project  { width: 100px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.col-name     { min-width: 260px; max-width: 360px; }
.col-status   { width: 130px; }
.col-reported { width: 110px; white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--text-muted); }
.col-reporter { width: 150px; }
.col-assigned { width: 170px; }
.col-emp      { width: 150px; }
.col-actions  { width: 48px; text-align: right; }

.col-due.overdue {
  color: var(--urgent);
  font-weight: 600;
}

.task-name {
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
}

.link {
  color: var(--accent);
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  display: inline-block;
  max-width: 100%;
  vertical-align: middle;
}
.link:hover { text-decoration: underline; }

.link-icon-inline {
  color: var(--text-subtle);
  text-decoration: none;
  font-size: 11px;
  margin-left: 4px;
}
.link-icon-inline:hover { color: var(--accent); }

.img-badge {
  font-size: 11px;
  margin-left: 4px;
  opacity: 0.7;
}

/* ─── Pills ──────────────────────────────────────────── */
.pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 500;
  line-height: 1.4;
  letter-spacing: 0.01em;
}

.pill-p-urgent { color: var(--urgent);  background: var(--urgent-bg); }
.pill-p-high   { color: var(--high);    background: var(--high-bg); }
.pill-p-normal { color: var(--normal);  background: var(--normal-bg); }
.pill-p-low    { color: var(--low);     background: var(--low-bg); }

.pill-s-todo         { color: var(--status-todo);      background: var(--status-todo-bg); }
.pill-s-in_progress  { color: var(--status-progress);  background: var(--status-progress-bg); }
.pill-s-on_hold      { color: var(--status-hold);      background: var(--status-hold-bg); }
.pill-s-completed    { color: var(--status-done);      background: var(--status-done-bg); }
.pill-s-canceled     { color: var(--status-cancel);    background: var(--status-cancel-bg); }

.pill-editable {
  border: none;
  cursor: pointer;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding-right: 6px;
  transition: filter 0.12s, transform 0.06s;
}
.pill-editable:hover {
  filter: brightness(0.96);
}
.pill-editable:active { transform: translateY(1px); }
.pill-editable.is-saving { opacity: 0.6; pointer-events: none; }

.pill-caret {
  font-size: 8px;
  line-height: 1;
  opacity: 0.55;
  margin-left: 2px;
  transform: translateY(-0.5px);
}

.status-menu {
  position: absolute;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  padding: 4px;
  z-index: 200;
  min-width: 160px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.status-menu-item {
  background: none;
  border: none;
  border-radius: 5px;
  padding: 6px 8px;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  transition: background 0.1s;
  display: flex;
  align-items: center;
}
.status-menu-item:hover { background: var(--surface-hover); }
.status-menu-item.selected {
  background: var(--accent-soft);
}
.status-menu-item.selected::after {
  content: '✓';
  margin-left: auto;
  color: var(--accent);
  font-weight: 700;
}

.btn-icon {
  background: none;
  border: none;
  color: var(--text-subtle);
  cursor: pointer;
  padding: 5px 6px;
  border-radius: 4px;
  font-size: 14px;
  line-height: 1;
  transition: all 0.12s;
}
.btn-icon:hover { color: var(--accent); background: var(--accent-soft); }
.btn-icon.delete:hover { color: var(--urgent); background: rgba(220, 38, 38, 0.08); }

.empty {
  text-align: center;
  padding: 80px 20px;
  color: var(--text-muted);
  font-size: 13px;
}
.empty a { color: var(--accent); }

.hidden { display: none !important; }

.reset-columns-bar {
  padding: 8px 28px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  font-size: 12px;
}

/* ─── Pagination ─────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 14px 28px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  font-size: 12px;
  color: var(--text-muted);
}

.pg-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 30px;
  height: 30px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  transition: all 0.12s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.pg-btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}
.pg-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.pg-page {
  padding: 0 10px;
  font-weight: 500;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.pg-info {
  margin-left: auto;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* ─── Dialog ─────────────────────────────────────────── */
dialog {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px;
  width: 720px;
  max-width: 92vw;
  box-shadow: var(--shadow-lg);
  margin: auto;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

dialog::backdrop {
  background: rgba(20, 40, 60, 0.4);
  backdrop-filter: blur(2px);
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

dialog h2 {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0;
}

.btn-close {
  background: none;
  border: none;
  font-size: 22px;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: all 0.12s;
}
.btn-close:hover { color: var(--text); background: var(--surface-alt); }

dialog label {
  display: block;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 5px;
  margin-top: 14px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
dialog label:first-of-type { margin-top: 0; }

dialog input[type="text"],
dialog input[type="url"],
dialog textarea,
dialog select,
dialog input[type="date"] {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

dialog select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%2394A0A8' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

dialog input:focus,
dialog textarea:focus,
dialog select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.form-row {
  display: flex;
  gap: 12px;
}

.form-col {
  flex: 1;
  min-width: 0;
}

.image-upload-area { margin-top: 14px; }

.image-upload-area label:first-child {
  display: block;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.image-preview {
  position: relative;
  margin-bottom: 8px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  max-height: 220px;
}

.image-preview img {
  width: 100%;
  max-height: 220px;
  object-fit: contain;
  display: block;
  background: var(--surface-alt);
}

.image-preview .btn-icon {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(255, 255, 255, 0.95);
  color: var(--text);
  border-radius: 50%;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.12);
}
.image-preview .btn-icon:hover { background: var(--urgent); color: #fff; }

.image-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.image-or {
  font-size: 12px;
  color: var(--text-muted);
}

.image-url-input {
  flex: 1;
  min-width: 200px;
}

.btn-upload {
  display: inline-block;
  cursor: pointer;
  text-align: center;
  white-space: nowrap;
}

.upload-status {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

/* ─── Toast ──────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--text);
  color: #fff;
  padding: 10px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 12px 32px rgba(20, 40, 60, 0.24);
  z-index: 100;
  animation: slideUp 0.2s ease;
}

@keyframes slideUp {
  from { transform: translateY(12px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ─── Searchable select ──────────────────────────────── */
.searchable-select { position: relative; }

.searchable-select input[type="text"] {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: var(--radius);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.searchable-select input[type="text"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.ss-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-top: 4px;
  max-height: 240px;
  overflow-y: auto;
  z-index: 20;
  box-shadow: var(--shadow-lg);
}

.ss-option {
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.08s;
  border-bottom: 1px solid var(--border);
}
.ss-option:last-child { border-bottom: none; }

.ss-option:hover, .ss-option.active {
  background: var(--surface-hover);
  color: var(--accent);
}

.ss-option.selected { color: var(--accent); font-weight: 500; }

.ss-empty {
  padding: 10px 12px;
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
}

/* ─── Custom scrollbar (webkit) ──────────────────────── */
.table-wrap::-webkit-scrollbar { height: 10px; }
.table-wrap::-webkit-scrollbar-track { background: var(--bg); }
.table-wrap::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 5px;
  border: 2px solid var(--bg);
}
.table-wrap::-webkit-scrollbar-thumb:hover { background: var(--text-subtle); }

/* ─── Responsive ─────────────────────────────────────── */
@media (max-width: 1100px) {
  .app-header { padding: 14px 20px; }
  .status-tabs { padding: 0 20px; }
  .filter-bar { padding: 10px 20px; }
  .pagination { padding: 12px 20px; }
  .task-table th, .task-table td { padding-left: 12px; padding-right: 12px; }
}

@media (max-width: 720px) {
  .app-header { padding: 12px 16px; }
  h1 { font-size: 16px; }
  .brand-logo { height: 28px; }
  .status-tabs { padding: 0 16px; }
  .status-tab { padding: 12px 4px; margin: 0 8px; font-size: 12.5px; }
  .filter-bar { padding: 10px 16px; }
  .filter-select { min-width: 120px; font-size: 12px; }
  .filter-search { max-width: 100%; }
  .pagination { padding: 12px 16px; }

  dialog {
    width: 100vw;
    max-width: 100vw;
    max-height: 100vh;
    height: 100vh;
    border-radius: 0;
    margin: 0;
    top: 0;
    left: 0;
    transform: none;
    overflow-y: auto;
    padding: 20px;
  }

  body.dialog-open {
    overflow: hidden;
    position: fixed;
    width: 100%;
  }

  .form-row { flex-direction: column; gap: 0; }
}
