:root {
  --navy: #0b3a5c;
  --blue: #1b9ad6;
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1e2a36;
  --muted: #6b7a8d;
  --line: #dfe6ee;
  --danger: #c0392b;
  --ok: #1e8e4d;
  --warn: #b7791f;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--navy); }

.topbar { display: flex; align-items: center; gap: 24px; background: var(--navy); color: #fff; padding: 10px 20px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: #fff; }
.brand img { height: 44px; background: #fff; border-radius: 8px; padding: 4px 8px; }
.brand strong { display: block; font-size: 20px; }
.brand small { display: block; font-size: 11px; color: #bcd7ea; }
.mainnav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.mainnav a { color: #dceaf5; text-decoration: none; padding: 8px 10px; border-radius: 6px; font-size: 14px; }
.mainnav a:hover { background: rgba(255,255,255,.15); color: #fff; }
.userbox { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.userbox em { color: #bcd7ea; font-style: normal; font-size: 12px; }

.container { max-width: 1100px; margin: 0 auto; padding: 24px 16px 60px; }
h1 { margin: 0 0 4px; }
h2 { margin-top: 0; font-size: 18px; }
.muted { color: var(--muted); }
.page-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; flex-wrap: wrap; gap: 8px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 18px; margin-bottom: 16px; }
.error-card { border-color: var(--danger); }

.flash { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; }
.flash.success { background: #e6f6ec; border: 1px solid #9ed4ae; }
.flash.error { background: #fdecea; border: 1px solid #f0a8a0; }
.flash ul { margin: 0; padding-left: 18px; }

.btn { display: inline-block; padding: 8px 16px; border-radius: 6px; border: 1px solid var(--line); background: #fff; color: var(--text); text-decoration: none; cursor: pointer; font-size: 14px; }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn.danger { color: var(--danger); border-color: #eec5c0; }

.table-wrap { overflow-x: auto; background: #fff; border: 1px solid var(--line); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: #f0f4f8; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
tr.is-overdue td { background: #fdf3f2; }
td.actions { white-space: nowrap; }
td.actions form { display: inline; }

.form label { display: block; margin-bottom: 12px; font-weight: 600; font-size: 14px; }
.form input, .form select, .form textarea, .filter select, .inline-form input, .inline-form select {
  display: block; width: 100%; margin-top: 4px; padding: 9px 10px; border: 1px solid var(--line);
  border-radius: 6px; font-size: 14px; font-family: inherit; background: #fff;
}
.form .row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
fieldset { border: 1px solid var(--line); border-radius: 6px; margin-bottom: 12px; }
legend { font-size: 14px; font-weight: 600; padding: 0 6px; }
label.check { display: inline-flex; align-items: center; gap: 6px; font-weight: normal; margin: 6px 12px 6px 0; }
label.check input { width: auto; margin: 0; }
.inline-form { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.inline-form label { margin-bottom: 0; min-width: 130px; }
.inline-form label.grow { flex: 1; min-width: 220px; }
.filter { margin-bottom: 12px; }
.filter select { width: auto; display: inline-block; }

.pill { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 12px; background: #e8eef4; }
.pill.in_progress, .pill.sent { background: #fff3d6; color: #7a5c00; }
.pill.done, .pill.paid, .pill.completed, .pill.won, .pill.admin { background: #e0f3e8; color: #146636; }
.pill.overdue, .pill.on_hold, .pill.lost, .pill.team { background: #fdecea; color: #a93226; }
.pill.new, .pill.todo, .pill.contacted, .pill.proposal, .pill.draft, .pill.cancelled { background: #e8eef4; color: #44586c; }
.pill.manager { background: #e0edf7; color: #0b5a8e; font-weight: 700; }
.role-form { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; align-items: center; }
.role-form select { font-size: 12px; padding: 4px 6px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { text-align: center; }
.stat strong { display: block; font-size: 32px; color: var(--navy); }
.stat span { color: var(--muted); font-size: 13px; }

.brief-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
.brief-list { list-style: none; margin: 0; padding: 0; }
.brief-list li { padding: 8px 0; border-bottom: 1px dashed var(--line); }
.brief-list li:last-child { border-bottom: none; }
.brief-list li.overdue a, .brief-list li.overdue { color: var(--danger); }
.brief-list small { display: block; color: var(--muted); }

.auth-wrap { display: flex; justify-content: center; padding-top: 40px; }
.auth-card { max-width: 420px; width: 100%; text-align: center; }
.auth-logo { height: 64px; margin-bottom: 8px; }
.auth-card form { text-align: left; }
.auth-card label { display: block; margin-bottom: 12px; font-weight: 600; font-size: 14px; }
.auth-card input { display: block; width: 100%; margin-top: 4px; padding: 10px; border: 1px solid var(--line); border-radius: 6px; font-size: 15px; }
.auth-card .btn.primary { width: 100%; padding: 12px; font-size: 16px; }

.rule-body { white-space: pre-wrap; }

.footer { text-align: center; padding: 24px; color: var(--muted); font-size: 13px; border-top: 1px solid var(--line); background: #fff; }

/* ---- header search + notifications bell ---- */
.searchbar { margin-left: auto; }
.searchbar input[type="search"] {
  width: 220px; padding: 8px 12px; border: 1px solid rgba(255,255,255,.35);
  border-radius: 20px; background: rgba(255,255,255,.12); color: #fff; font-size: 13px;
}
.searchbar input[type="search"]::placeholder { color: #bcd7ea; }
.bell { position: relative; font-size: 20px; text-decoration: none; padding: 6px 8px; }
.bell .badge {
  position: absolute; top: 0; right: 0; background: #e74c3c; color: #fff;
  font-size: 10px; font-weight: 700; border-radius: 10px; padding: 1px 6px;
}

/* ---- quick actions + tabs ---- */
.quick-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.tabs { display: flex; gap: 4px; margin-bottom: 12px; }
.tabs a { padding: 8px 16px; border: 1px solid var(--line); border-bottom: none; border-radius: 8px 8px 0 0;
  text-decoration: none; color: var(--muted); background: #eef2f6; font-size: 14px; }
.tabs a.active { background: #fff; color: var(--navy); font-weight: 700; }

/* ---- kanban ---- */
.kanban { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; align-items: start; }
.kanban-col { background: #eef2f6; border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.kanban-col h2 { font-size: 15px; }
.kanban-card { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin-bottom: 10px; }
.kanban-card a { text-decoration: none; }
.kanban-meta { margin: 6px 0; display: flex; gap: 6px; flex-wrap: wrap; }
.kanban-card small { display: block; margin-top: 4px; }
.kanban-move { display: flex; gap: 6px; margin-top: 8px; }
.kanban-move form { display: inline; }

/* ---- calendar ---- */
.cal-nav { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.calendar { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 8px; }
.cal-head { font-size: 11px; text-transform: uppercase; color: var(--muted); text-align: center; padding: 6px 0; font-weight: 700; }
.cal-day { min-height: 90px; border: 1px solid var(--line); border-radius: 6px; padding: 4px; font-size: 13px; }
.cal-day.empty { border: none; background: transparent; }
.cal-day.is-today { border-color: var(--blue); background: #f0f9ff; }
.cal-num { font-weight: 700; color: var(--muted); font-size: 12px; }
.cal-task { display: block; font-size: 11px; text-decoration: none; border-radius: 4px; padding: 2px 4px; margin-top: 3px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #1e2a36; background: #e8eef4; }
.cal-task.st-done { text-decoration: line-through; opacity: .6; }
.cal-task.st-in_progress { background: #fff3d6; }

/* ---- detail pages ---- */
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 8px; margin: 12px 0; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.comment { border-bottom: 1px dashed var(--line); padding: 8px 0; }
.comment:last-of-type { border-bottom: none; }
.comment-head { margin-bottom: 4px; }
.comment p { margin: 4px 0 8px; white-space: pre-wrap; }
.text-danger { color: var(--danger); }

/* ---- extra pills ---- */
.pill.pr-low { background: #e8eef4; color: #44586c; }
.pill.pr-medium { background: #e0edf7; color: #0b5a8e; }
.pill.pr-high { background: #fff3d6; color: #7a5c00; }
.pill.pr-urgent { background: #fdecea; color: #a93226; font-weight: 700; }
.pill.ntf-task_assigned { background: #e0edf7; color: #0b5a8e; }
.pill.ntf-overdue { background: #fdecea; color: #a93226; }
.pill.ntf-invite { background: #e0f3e8; color: #146636; }
.pill.ntf-project_assigned { background: #e0edf7; color: #0b5a8e; }
tr.is-new td { background: #f0f9ff; }

/* ---- invoice print ---- */
.invoice-head { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 12px; }
.invoice-meta div { margin-bottom: 4px; }
.invoice-total { font-size: 20px; text-align: right; }

@media print {
  .topbar, .footer, .no-print, .flash { display: none !important; }
  body { background: #fff; }
  .container { max-width: 100%; padding: 0; }
  .card { border: none; margin: 0; padding: 0; }
  .table-wrap { border: none; }
  a { color: #000; text-decoration: none; }
}

@media (max-width: 640px) {
  .form .row { grid-template-columns: 1fr; }
  .topbar { gap: 12px; }
  .searchbar { order: 3; width: 100%; margin-left: 0; }
  .searchbar input[type="search"] { width: 100%; }
  .mainnav { order: 2; width: 100%; }
  .mainnav a { padding: 12px 10px; }
  .userbox { margin-left: auto; }
  .btn { min-height: 44px; padding: 12px 18px; display: inline-flex; align-items: center; }
  .btn.small { min-height: 44px; padding: 10px 14px; font-size: 14px; }
  .form input, .form select, .form textarea, .filter select, .inline-form input, .inline-form select {
    padding: 12px 10px; font-size: 16px; /* 16px avoids iOS zoom */
  }
  .inline-form { flex-direction: column; align-items: stretch; }
  .inline-form label { min-width: 0; }
  .two-col { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .quick-actions .btn { flex: 1 1 45%; justify-content: center; }
  .calendar { grid-template-columns: repeat(7, minmax(38px, 1fr)); padding: 4px; gap: 2px; }
  .cal-day { min-height: 64px; font-size: 11px; }
  .cal-task { font-size: 10px; }

  /* stacked tables */
  table.stacked, table.stacked thead, table.stacked tbody, table.stacked th,
  table.stacked td, table.stacked tr { display: block; }
  table.stacked thead { display: none; }
  table.stacked tr { border-bottom: 2px solid var(--line); padding: 4px 0; }
  table.stacked td { border: none; border-bottom: 1px dashed var(--line); padding: 10px 10px 10px 42%; position: relative; min-height: 44px; }
  table.stacked td:last-child { border-bottom: none; }
  table.stacked td::before {
    content: attr(data-label); position: absolute; left: 10px; top: 12px;
    font-weight: 700; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em;
  }
  table.stacked td.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
  table.stacked td.actions::before { position: static; margin-right: 4px; }
}
