/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
  border: 1px solid transparent;
  flex-shrink: 0;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-h); }

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

.btn-danger { background: var(--red-lo); border-color: var(--red); color: var(--red); }
.btn-danger:hover { background: var(--red); color: #fff; }

.btn-ghost { color: var(--text2); }
.btn-ghost:hover { background: var(--surface2); color: var(--text); }

.btn-sm { height: 28px; padding: 0 10px; font-size: 12px; }
.btn-xs { height: 24px; padding: 0 8px; font-size: 11px; border-radius: 5px; }

.btn[disabled] { opacity: .4; cursor: not-allowed; }

/* ── Inputs ───────────────────────────────────────────────────────────────── */
.field-group { display: flex; flex-direction: column; gap: 4px; }
.field-label { font-size: 11px; font-weight: 500; color: var(--text3); }

.input {
  width: 100%;
  height: 34px;
  padding: 0 10px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text);
  transition: border-color .12s;
}
.input:focus { border-color: var(--accent); }
.input::placeholder { color: var(--text3); }

.textarea {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text);
  resize: vertical;
  min-height: 80px;
  transition: border-color .12s;
  line-height: 1.5;
}
.textarea:focus { border-color: var(--accent); }
.textarea::placeholder { color: var(--text3); }

.select {
  width: 100%;
  height: 34px;
  padding: 0 10px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' fill='none'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%234a5578' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
  cursor: pointer;
  transition: border-color .12s;
}
.select:focus { border-color: var(--accent); }

.input-row { display: flex; gap: 8px; }
.input-row .field-group { flex: 1; }

/* ── Modals ───────────────────────────────────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(3px);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}
.overlay.open { opacity: 1; pointer-events: all; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--radius-lg);
  padding: 24px;
  width: 480px;
  max-width: 95vw;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  transform: scale(.96);
  transition: transform .2s;
}
.overlay.open .modal { transform: scale(1); }

.modal-lg { width: 640px; }

.modal-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 20px;
  color: var(--text);
}

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

.modal-body { display: flex; flex-direction: column; gap: 14px; }

/* ── Form sections ────────────────────────────────────────────────────────── */
.form-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.form-divider {
  font-size: 11px;
  font-weight: 600;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
  margin: 4px 0;
}

/* ── Table ────────────────────────────────────────────────────────────────── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.data-table th {
  text-align: left;
  padding: 8px 12px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: .06em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text2);
  vertical-align: middle;
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--surface2); }

/* ── Toasts ───────────────────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9000;
  pointer-events: none;
}

.toast {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: 10px 16px;
  font-size: 13px;
  color: var(--text);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 8px;
  animation: toastIn .2s ease;
  white-space: nowrap;
}

.toast.success { border-color: var(--green); }
.toast.error   { border-color: var(--red);   }
.toast.info    { border-color: var(--accent); }

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

/* ── Stats / KPI cards ────────────────────────────────────────────────────── */
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-label { font-size: 11px; color: var(--text3); font-weight: 500; }
.stat-value { font-size: 22px; font-weight: 700; color: var(--text); }
.stat-sub   { font-size: 11px; color: var(--text2); }

/* ── Scrollbar ────────────────────────────────────────────────────────────── */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border2) transparent;
}
*::-webkit-scrollbar { width: 5px; height: 5px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }

/* ── Module list panel ────────────────────────────────────────────────────── */
.module-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.module-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background .1s;
}
.module-list-item:hover { background: var(--surface2); }

.module-list-title { font-size: 12px; font-weight: 500; color: var(--text); }
.module-list-sub   { font-size: 11px; color: var(--text3); margin-top: 1px; }

.module-list-add {
  opacity: 0;
  width: 22px; height: 22px;
  border-radius: 5px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text2);
  transition: opacity .1s, background .1s;
  flex-shrink: 0;
}
.module-list-item:hover .module-list-add { opacity: 1; }
.module-list-add:hover { background: var(--border); color: var(--text); }

.module-list-del {
  opacity: 0;
  width: 22px; height: 22px;
  border-radius: 5px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text3);
  transition: opacity .1s, background .1s, color .1s;
  flex-shrink: 0;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}
.module-list-item:hover .module-list-del { opacity: 1; }
.module-list-del:hover { background: rgba(239,68,68,.12); color: #ef4444; }

/* ── Search ───────────────────────────────────────────────────────────────── */
.search-wrap {
  position: relative;
}
.search-wrap svg {
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  color: var(--text3);
}
.search-wrap .input { padding-left: 30px; }

/* ── Empty state ──────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text3);
}
.empty-state-icon { font-size: 32px; margin-bottom: 10px; }
.empty-state-title { font-size: 14px; font-weight: 600; color: var(--text2); margin-bottom: 4px; }
.empty-state-sub   { font-size: 12px; }

/* ── Calendar (Agenda) ────────────────────────────────────────────────────── */
.cal-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  gap: 6px;
}
.cal-month-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text1);
  flex: 1;
  text-align: center;
}
.cal-toolbar button {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text2);
  cursor: pointer;
  font-size: 13px;
  padding: 3px 8px;
  line-height: 1;
}
.cal-toolbar button:hover { background: var(--bg3); }

.cal-week-header {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  margin-bottom: 2px;
}
.cal-wlabel {
  text-align: center;
  font-size: 10px;
  font-weight: 600;
  color: var(--text3);
  padding: 2px 0;
  text-transform: uppercase;
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  margin-bottom: 12px;
}
.cal-day {
  border-radius: 6px;
  padding: 3px 2px 2px;
  cursor: pointer;
  min-height: 36px;
  position: relative;
  transition: background .12s;
}
.cal-day:hover { background: var(--bg3); }
.cal-day.today { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.cal-day.today .cal-day-num { color: var(--accent); font-weight: 700; }
.cal-day.selected { background: var(--accent) !important; }
.cal-day.selected .cal-day-num { color: #fff; font-weight: 700; }
.cal-day.selected .cal-dot { opacity: .7; }
.cal-day-empty { min-height: 36px; }
.cal-day-num {
  font-size: 11px;
  color: var(--text2);
  text-align: center;
  line-height: 1;
  margin-bottom: 3px;
}

.cal-dots {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 2px;
  min-height: 6px;
}
.cal-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  flex-shrink: 0;
}

.cal-events-section { margin-top: 4px; }
.cal-events-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 6px;
}
.cal-events-empty {
  font-size: 12px;
  color: var(--text3);
  text-align: center;
  padding: 12px 0;
}

.cal-event-item {
  display: flex;
  align-items: stretch;
  gap: 8px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 6px;
  cursor: pointer;
  transition: background .12s;
}
.cal-event-item:hover { background: var(--bg3); }
.cal-event-stripe {
  width: 3px;
  border-radius: 2px;
  flex-shrink: 0;
  align-self: stretch;
  min-height: 100%;
}
.cal-event-info { flex: 1; min-width: 0; }
.cal-event-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cal-event-meta {
  font-size: 11px;
  color: var(--text3);
  margin-top: 2px;
}
.cal-event-del {
  background: none;
  border: none;
  color: var(--text3);
  cursor: pointer;
  font-size: 14px;
  padding: 0 2px;
  line-height: 1;
  align-self: center;
  opacity: 0;
  transition: opacity .12s;
}
.cal-event-item:hover .cal-event-del { opacity: 1; }
.cal-event-del:hover { color: #ef4444; }

/* ── Projects list ────────────────────────────────────────────────────────── */
.proj-item {
  display: flex;
  align-items: stretch;
  gap: 0;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 7px;
  cursor: pointer;
  overflow: hidden;
  transition: background .12s;
}
.proj-item:hover { background: var(--bg3); }
.proj-item-bar {
  width: 4px;
  flex-shrink: 0;
}
.proj-item-body {
  flex: 1;
  padding: 8px 10px;
  min-width: 0;
}
.proj-item-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}
.proj-item-badges {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  margin-bottom: 5px;
}
.proj-progress-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}
.proj-progress-bar {
  flex: 1;
  height: 4px;
  background: var(--bg3);
  border-radius: 2px;
  overflow: hidden;
}
.proj-progress-fill {
  height: 100%;
  border-radius: 2px;
  transition: width .3s;
}
.proj-progress-label {
  font-size: 10px;
  color: var(--text3);
  white-space: nowrap;
}

/* ── Kanban ───────────────────────────────────────────────────────────────── */
.kanban-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}
.kanban-edit-bar {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.kanban-col {
  margin-bottom: 12px;
}
.kanban-col-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 8px;
  border-radius: 6px 6px 0 0;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-bottom: none;
  margin-bottom: 0;
}
.kanban-col-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.kanban-col-count {
  font-size: 11px;
  color: var(--text3);
  background: var(--bg3);
  border-radius: 10px;
  padding: 1px 6px;
}
.kanban-task {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 8px;
  background: var(--bg1);
  border: 1px solid var(--border);
  border-top: none;
  cursor: pointer;
  transition: background .1s;
}
.kanban-task:hover { background: var(--bg2); }
.task-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}
.task-body {
  flex: 1;
  min-width: 0;
}
.task-title {
  font-size: 12px;
  color: var(--text1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.task-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
  flex-wrap: wrap;
}
.task-assignee {
  font-size: 10px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-lo);
  padding: 1px 5px;
  border-radius: 10px;
}
.task-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity .12s;
}
.kanban-task:hover .task-actions { opacity: 1; }
.task-advance, .task-del-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 1px 3px;
  border-radius: 4px;
  color: var(--text3);
}
.task-advance:hover { color: var(--accent); background: var(--accent-lo); }
.task-del-btn:hover  { color: #ef4444; }
.kanban-add-btn {
  display: block;
  width: 100%;
  padding: 5px 8px;
  background: var(--bg1);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 6px 6px;
  font-size: 11px;
  color: var(--text3);
  cursor: pointer;
  text-align: left;
  transition: background .1s, color .1s;
}
.kanban-add-btn:hover { background: var(--bg2); color: var(--text2); }

/* ── Mobile overrides ─────────────────────────────────────────────────────── */
@media (max-width: 767px) {
  /* Modals slide up as bottom sheets */
  .overlay {
    align-items: flex-end;
    padding: 0;
  }
  .modal, .modal-lg {
    width: 100%;
    max-width: 100%;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    max-height: 92dvh;
    transform: translateY(12px);
    padding: 20px 16px 24px;
    padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  }
  .overlay.open .modal,
  .overlay.open .modal-lg { transform: translateY(0); }

  /* Prevent iOS input auto-zoom */
  input, select, textarea { font-size: 16px !important; }

  /* Touch-friendly tap targets */
  .btn { min-height: 40px; }
  .module-list-add { width: 32px; height: 32px; }

  /* Panel body smooth scroll */
  .panel-body { -webkit-overflow-scrolling: touch; }

  /* Cards min-width for small screens */
  .card { min-width: 200px; }
}

/* ── Flow form stages ─────────────────────────────────────────────────────── */
.flow-form-stages {
  display: flex;
  align-items: flex-start;
  gap: 4px;
  padding: 8px 0;
  overflow-x: auto;
}
.flow-form-stages::-webkit-scrollbar { display: none; }
.flow-form-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  flex: 1;
  min-width: 72px;
}
.flow-form-stage-icon {
  font-size: 20px;
  line-height: 1;
}
.flow-form-stage-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  text-align: center;
}
.flow-form-stage-sub {
  font-size: 9px;
  color: var(--text3);
  text-align: center;
  line-height: 1.3;
  min-height: 22px;
}
.flow-form-stage .input {
  width: 100%;
  text-align: center;
  padding: 4px 6px;
  font-size: 12px;
}
.flow-form-stage-unit {
  font-size: 9px;
  color: var(--text3);
}
.flow-form-arrow {
  flex-shrink: 0;
  color: var(--text3);
  font-size: 14px;
  margin-top: 28px;
  padding: 0 2px;
}
