/* ==========================================================================
   Taj Al Mada — Upgraded Modern Task Management System (Board / List / Focus)
   ========================================================================== */

@media screen {
  .tm-header-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
  }

  .tm-view-switch {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 4px;
    border-radius: 12px;
    background: var(--surface);
    border: 1px solid var(--line);
    box-shadow: var(--shadow-sm);
  }

  .tm-view-switch button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 34px;
    padding: 6px 13px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
  }

  .tm-view-switch button:hover {
    color: var(--ink);
    background: var(--surface-hover);
  }

  .tm-view-switch button[aria-pressed="true"] {
    background: #102441;
    color: #ffffff;
    box-shadow: 0 2px 6px rgba(16, 36, 65, 0.2);
  }

  [data-theme="dark"] .tm-view-switch button[aria-pressed="true"] {
    background: #2563eb;
  }

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

  /* Compact Executive KPI Strip */
  .tm-kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 16px;
  }

  .tm-kpi {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 15px 18px;
    border-radius: 14px;
    background: var(--surface);
    border: 1px solid var(--line);
    text-align: left;
    color: var(--ink);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: transform 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
  }

  .tm-kpi:hover {
    transform: translateY(-2px);
    border-color: var(--line-strong);
    box-shadow: var(--shadow-md);
  }

  .tm-kpi[aria-pressed="true"] {
    border-color: #2563eb;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.18);
  }

  .tm-kpi-meta span {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    margin-bottom: 4px;
  }

  .tm-kpi-meta strong {
    font-size: 26px;
    line-height: 1.1;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
  }

  .tm-kpi-meta small {
    display: inline-block;
    margin-left: 6px;
    font-size: 11.5px;
    font-weight: 600;
    color: var(--muted);
  }

  .tm-kpi-icon {
    width: 40px;
    height: 40px;
    border-radius: 11px;
    display: grid;
    place-items: center;
    flex: none;
  }

  .tm-kpi.k-all .tm-kpi-icon { background: #eff6ff; color: #2563eb; }
  .tm-kpi.k-active .tm-kpi-icon { background: #f5f3ff; color: #7c3aed; }
  .tm-kpi.k-overdue .tm-kpi-icon { background: #fef2f2; color: #dc2626; }
  .tm-kpi.k-overdue strong { color: #dc2626; }
  .tm-kpi.k-done .tm-kpi-icon { background: #ecfdf5; color: #16a34a; }
  .tm-kpi.k-done strong { color: #16a34a; }

  [data-theme="dark"] .tm-kpi.k-all .tm-kpi-icon { background: rgba(37, 99, 235, 0.18); color: #93c5fd; }
  [data-theme="dark"] .tm-kpi.k-active .tm-kpi-icon { background: rgba(139, 92, 246, 0.18); color: #c4b5fd; }
  [data-theme="dark"] .tm-kpi.k-overdue .tm-kpi-icon { background: rgba(239, 68, 68, 0.18); color: #fca5a5; }
  [data-theme="dark"] .tm-kpi.k-overdue strong { color: #fca5a5; }
  [data-theme="dark"] .tm-kpi.k-done .tm-kpi-icon { background: rgba(22, 163, 74, 0.18); color: #86efac; }
  [data-theme="dark"] .tm-kpi.k-done strong { color: #86efac; }

  /* Inline Quick-Add Task Composer */
  .tm-quick-bar {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(170px, 1.2fr) 150px 125px auto;
    gap: 8px;
    padding: 12px 14px;
    margin-bottom: 14px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: var(--shadow-sm);
    align-items: center;
  }

  .tm-quick-bar input,
  .tm-quick-bar select {
    min-height: 38px;
    padding: 6px 10px;
    font-size: 13.5px;
    border-radius: 9px;
  }

  .tm-quick-bar .app-date-picker {
    gap: 4px;
  }

  .tm-quick-bar .app-date-picker select {
    padding: 5px 4px;
    font-size: 12px;
  }

  .tm-quick-bar button[type="submit"] {
    min-height: 38px;
    padding: 6px 16px;
    white-space: nowrap;
  }

  /* Filter & Sort Toolbar */
  .tm-filter-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    margin-bottom: 16px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: var(--shadow-sm);
  }

  .tm-filter-bar input[type="search"] {
    flex: 1.5 1 200px;
    min-height: 36px;
    font-size: 13.5px;
  }

  .tm-filter-bar select {
    flex: 1 1 130px;
    min-height: 36px;
    font-size: 13px;
  }

  .tm-filter-bar button {
    min-height: 36px;
    font-size: 13px;
    padding: 5px 12px;
  }

  /* ========================================================================
     1. KANBAN BOARD VIEW
     ======================================================================== */
  .tm-board {
    display: grid;
    grid-template-columns: repeat(4, minmax(260px, 1fr));
    gap: 14px;
    align-items: start;
    overflow-x: auto;
    padding-bottom: 8px;
  }

  .tm-col {
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 12px;
    min-height: 320px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  }

  .tm-col.drag-over {
    background: var(--accent-soft);
    border-color: #2563eb;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
  }

  .tm-col-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 4px 4px 8px;
    border-bottom: 2px solid var(--line);
  }

  .tm-col[data-col="new"] .tm-col-head { border-bottom-color: #3b82f6; }
  .tm-col[data-col="progress"] .tm-col-head { border-bottom-color: #8b5cf6; }
  .tm-col[data-col="waiting"] .tm-col-head { border-bottom-color: #f59e0b; }
  .tm-col[data-col="completed"] .tm-col-head { border-bottom-color: #10b981; }

  .tm-col-title {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: 13.5px;
    font-weight: 700;
    color: var(--ink);
  }

  .tm-col-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
  }

  .tm-col[data-col="new"] .tm-col-dot { background: #3b82f6; }
  .tm-col[data-col="progress"] .tm-col-dot { background: #8b5cf6; }
  .tm-col[data-col="waiting"] .tm-col-dot { background: #f59e0b; }
  .tm-col[data-col="completed"] .tm-col-dot { background: #10b981; }

  .tm-col-count {
    font-size: 11.5px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 99px;
    background: var(--surface);
    border: 1px solid var(--line);
    color: var(--muted);
    font-variant-numeric: tabular-nums;
  }

  .tm-col-cards {
    display: flex;
    flex-direction: column;
    gap: 9px;
    flex: 1;
  }

  /* Kanban Task Card */
  .tm-card {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--line);
    border-left: 3.5px solid #3b82f6;
    border-radius: 12px;
    padding: 12px 12px 10px;
    box-shadow: var(--shadow-sm);
    cursor: grab;
    transition: transform 0.14s ease, box-shadow 0.14s ease, border-color 0.14s ease, opacity 0.14s ease;
  }

  .tm-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--line-strong);
  }

  .tm-card.dragging {
    opacity: 0.45;
    cursor: grabbing;
  }

  .tm-card.prio-urgent { border-left-color: #ef4444; }
  .tm-card.prio-high { border-left-color: #f59e0b; }
  .tm-card.prio-normal { border-left-color: #3b82f6; }
  .tm-card.prio-low { border-left-color: #94a3b8; }

  .tm-card.is-done {
    opacity: 0.78;
    border-left-color: #10b981;
  }

  .tm-card-top {
    display: flex;
    align-items: flex-start;
    gap: 8px;
  }

  /* 1-Click Complete Checkbox */
  .tm-check {
    flex: none;
    width: 20px;
    height: 20px;
    min-height: 20px;
    padding: 0;
    margin-top: 1px;
    border-radius: 50%;
    border: 1.8px solid var(--line-strong);
    background: transparent;
    color: transparent;
    display: inline-grid;
    place-items: center;
    font-size: 11px;
    font-weight: 800;
    cursor: pointer;
    transition: all 0.15s ease;
  }

  .tm-check:hover {
    border-color: #10b981;
    background: rgba(16, 185, 129, 0.1);
    color: #10b981;
  }

  .tm-check.checked {
    border-color: #10b981;
    background: #10b981;
    color: #ffffff;
  }

  .tm-card-title {
    flex: 1;
    min-width: 0;
    border: 0;
    background: transparent;
    padding: 0;
    min-height: 0;
    text-align: left;
    font-size: 13.5px;
    font-weight: 700;
    line-height: 1.35;
    color: var(--ink);
    cursor: pointer;
    overflow-wrap: anywhere;
  }

  .tm-card-title:hover {
    color: #2563eb;
  }

  .tm-card.is-done .tm-card-title {
    text-decoration: line-through;
    color: var(--muted);
  }

  .tm-card-client {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    margin-top: 6px;
    font-size: 12px;
    color: var(--muted);
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .tm-card-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-top: 9px;
  }

  .tm-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 7px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 700;
    line-height: 1.4;
    white-space: nowrap;
  }

  .tm-pill.due-overdue { background: #fee2e2; color: #b91c1c; }
  .tm-pill.due-today { background: #fef3c7; color: #92400e; }
  .tm-pill.due-ok { background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
  .tm-pill.platform { background: #eff6ff; color: #1d4ed8; }
  .tm-pill.prio-urgent { background: #fee2e2; color: #b91c1c; }
  .tm-pill.prio-high { background: #ffedd5; color: #c2410c; }
  .tm-pill.prio-normal { background: #eff6ff; color: #1d4ed8; }
  .tm-pill.prio-low { background: var(--surface-2); color: var(--muted); }
  .tm-pill.subtasks { background: #f0fdf4; color: #15803d; }
  .tm-pill.hold { background: #fef3c7; color: #92400e; }

  [data-theme="dark"] .tm-pill.due-overdue,
  [data-theme="dark"] .tm-pill.prio-urgent { background: rgba(239, 68, 68, 0.2); color: #fca5a5; }
  [data-theme="dark"] .tm-pill.due-today,
  [data-theme="dark"] .tm-pill.prio-high,
  [data-theme="dark"] .tm-pill.hold { background: rgba(245, 158, 11, 0.2); color: #fcd34d; }
  [data-theme="dark"] .tm-pill.platform,
  [data-theme="dark"] .tm-pill.prio-normal { background: rgba(59, 130, 246, 0.2); color: #93c5fd; }
  [data-theme="dark"] .tm-pill.subtasks { background: rgba(16, 185, 129, 0.2); color: #6ee7b7; }

  .tm-card-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid var(--line);
    font-size: 11.5px;
    color: var(--muted);
  }

  .tm-card-counters {
    display: inline-flex;
    align-items: center;
    gap: 8px;
  }

  .tm-avatar {
    display: inline-grid;
    place-items: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #102441;
    color: #f3cf80;
    font-size: 10px;
    font-weight: 800;
    flex: none;
  }

  [data-theme="dark"] .tm-avatar {
    background: #2563eb;
    color: #ffffff;
  }

  .tm-col-add {
    width: 100%;
    min-height: 34px;
    padding: 6px;
    border: 1px dashed var(--line-strong);
    border-radius: 9px;
    background: transparent;
    color: var(--muted);
    font-size: 12.5px;
    font-weight: 600;
  }

  .tm-col-add:hover {
    border-color: #2563eb;
    color: #2563eb;
    background: var(--accent-soft);
  }

  /* ========================================================================
     2. MODERN CLEAN LIST VIEW & FOCUS VIEW (Zero horizontal scroll!)
     ======================================================================== */
  .tm-section {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 14px;
    margin-bottom: 14px;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
  }

  .tm-section > summary {
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 16px;
    background: var(--surface-2);
    border-bottom: 1px solid var(--line);
    cursor: pointer;
    font-size: 14px;
    font-weight: 700;
    color: var(--ink);
  }

  .tm-section > summary::-webkit-details-marker {
    display: none;
  }

  .tm-section.sec-overdue > summary { border-left: 4px solid #ef4444; color: #b91c1c; }
  .tm-section.sec-today > summary { border-left: 4px solid #f59e0b; color: #92400e; }
  .tm-section.sec-active > summary { border-left: 4px solid #2563eb; }
  .tm-section.sec-done > summary { border-left: 4px solid #10b981; color: #15803d; }

  [data-theme="dark"] .tm-section.sec-overdue > summary { color: #fca5a5; }
  [data-theme="dark"] .tm-section.sec-today > summary { color: #fcd34d; }
  [data-theme="dark"] .tm-section.sec-done > summary { color: #6ee7b7; }

  .tm-row {
    display: grid;
    grid-template-columns: 24px minmax(0, 1.8fr) auto auto auto auto;
    align-items: center;
    gap: 10px 14px;
    padding: 11px 16px;
    border-bottom: 1px solid var(--line);
    transition: background-color 0.12s ease;
  }

  .tm-row:last-child {
    border-bottom: 0;
  }

  .tm-row:hover {
    background: var(--surface-hover);
  }

  .tm-row-main {
    min-width: 0;
  }

  .tm-row-title {
    display: block;
    border: 0;
    background: transparent;
    padding: 0;
    min-height: 0;
    text-align: left;
    font-size: 14px;
    font-weight: 700;
    color: var(--ink);
    cursor: pointer;
    overflow-wrap: anywhere;
  }

  .tm-row-title:hover {
    color: #2563eb;
  }

  .tm-row.is-done .tm-row-title {
    text-decoration: line-through;
    color: var(--muted);
  }

  .tm-row-sub {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-top: 3px;
    font-size: 12px;
    color: var(--muted);
  }

  .tm-status-select {
    width: auto;
    min-width: 128px;
    min-height: 32px;
    padding: 4px 8px;
    font-size: 12px;
    font-weight: 600;
    border-radius: 8px;
  }

  .tm-row-actions {
    display: inline-flex;
    align-items: center;
    gap: 5px;
  }

  .tm-icon-btn {
    width: 30px;
    height: 30px;
    min-height: 30px;
    padding: 0;
    display: inline-grid;
    place-items: center;
    border-radius: 7px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    color: var(--muted);
    font-size: 13px;
  }

  .tm-icon-btn:hover {
    color: var(--ink);
    border-color: var(--line-strong);
    background: var(--surface-hover);
  }

  .tm-icon-btn.del:hover {
    color: #dc2626;
    background: #fef2f2;
    border-color: #fecaca;
  }

  /* ========================================================================
     3. UPGRADED TASK DETAIL INSPECTOR DIALOG
     ======================================================================== */
  #task-dialog.tm-inspector {
    width: min(880px, calc(100vw - 24px));
    max-height: 92dvh;
    padding: 0;
    border-radius: 16px;
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--ink);
    overflow: hidden;
  }

  .tm-insp-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--line);
    background: var(--surface-2);
  }

  .tm-insp-head-left {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    min-width: 0;
    flex: 1;
  }

  .tm-insp-head h2 {
    margin: 0;
    font-size: 18px;
    line-height: 1.3;
    color: var(--ink);
    overflow-wrap: anywhere;
  }

  .tm-insp-body {
    display: grid;
    grid-template-columns: minmax(0, 1.55fr) minmax(240px, 1fr);
    max-height: calc(92dvh - 72px);
    overflow-y: auto;
  }

  .tm-insp-main {
    padding: 18px 20px;
    border-right: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    gap: 18px;
  }

  .tm-insp-side {
    padding: 18px 20px;
    background: var(--surface-2);
    display: flex;
    flex-direction: column;
    gap: 16px;
  }

  .tm-insp-block h3 {
    margin: 0 0 8px;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
  }

  .tm-pill-group {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }

  .tm-pill-btn {
    padding: 5px 10px;
    min-height: 30px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    background: var(--surface);
    border: 1px solid var(--line);
    color: var(--ink-soft);
  }

  .tm-pill-btn:hover {
    border-color: var(--line-strong);
  }

  .tm-pill-btn[aria-pressed="true"] {
    background: #102441;
    border-color: #102441;
    color: #ffffff;
  }

  [data-theme="dark"] .tm-pill-btn[aria-pressed="true"] {
    background: #2563eb;
    border-color: #2563eb;
  }

  /* Subtasks checklist */
  .tm-progress-bar {
    height: 7px;
    border-radius: 99px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    overflow: hidden;
    margin-bottom: 10px;
  }

  .tm-progress-bar i {
    display: block;
    height: 100%;
    background: linear-gradient(90deg, #10b981, #22c55e);
    border-radius: 99px;
    transition: width 0.25s ease;
  }

  .tm-subtask-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 10px;
  }

  .tm-subtask-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 10px;
    border-radius: 9px;
    background: var(--surface-2);
    border: 1px solid var(--line);
  }

  .tm-subtask-item span {
    flex: 1;
    font-size: 13.5px;
    overflow-wrap: anywhere;
  }

  .tm-subtask-item.done span {
    text-decoration: line-through;
    color: var(--muted);
  }

  .tm-inline-form {
    display: flex;
    gap: 6px;
  }

  .tm-inline-form input {
    flex: 1;
    min-height: 36px;
    font-size: 13px;
  }

  .tm-inline-form button {
    min-height: 36px;
    padding: 5px 12px;
    font-size: 13px;
  }

  /* Comments thread */
  .tm-comments {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 10px;
  }

  .tm-comment {
    padding: 9px 12px;
    border-radius: 10px;
    background: var(--surface-2);
    border: 1px solid var(--line);
  }

  .tm-comment-head {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    font-size: 11.5px;
    color: var(--muted);
    margin-bottom: 4px;
  }

  .tm-comment-head strong {
    color: var(--ink);
  }

  .tm-comment p {
    margin: 0;
    font-size: 13.5px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
  }

  /* Activity timeline */
  .tm-timeline {
    list-style: none;
    margin: 0;
    padding: 0 0 0 12px;
    border-left: 2px solid var(--line);
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .tm-timeline li {
    position: relative;
    font-size: 12px;
    color: var(--ink-soft);
    padding-left: 6px;
  }

  .tm-timeline li::before {
    content: "";
    position: absolute;
    left: -17px;
    top: 5px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #2563eb;
  }

  .tm-timeline small {
    display: block;
    color: var(--muted);
    font-size: 11px;
  }

  .tm-meta-dl {
    display: grid;
    gap: 10px;
    margin: 0;
  }

  .tm-meta-dl dt {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
  }

  .tm-meta-dl dd {
    margin: 2px 0 0;
    font-size: 13.5px;
    font-weight: 600;
    color: var(--ink);
  }

  @media (max-width: 1150px) {
    .tm-board {
      grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .tm-quick-bar {
      grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .tm-quick-bar button[type="submit"] {
      grid-column: 1 / -1;
    }
  }

  @media (max-width: 780px) {
    .tm-kpi-grid {
      grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .tm-board {
      grid-template-columns: 1fr;
    }
    .tm-quick-bar {
      grid-template-columns: 1fr;
    }
    .tm-row {
      grid-template-columns: 24px minmax(0, 1fr);
      gap: 8px;
      padding: 12px;
    }
    .tm-row-extra {
      grid-column: 2;
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      gap: 6px;
    }
    .tm-insp-body {
      grid-template-columns: 1fr;
    }
    .tm-insp-main {
      border-right: 0;
      border-bottom: 1px solid var(--line);
    }
  }
}
