* { box-sizing: border-box; }
body {
  font-family: -apple-system, "Segoe UI", Arial, sans-serif;
  background: #f5f5f7;
  color: #1a1a1a;
  margin: 0;
  line-height: 1.4;
}
nav {
  position: sticky;
  top: 0;
  z-index: 60;
  background: #1a1a2e;
  color: #fff;
  padding: 12px 20px;
  display: flex;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
}
nav a { color: #ccc; text-decoration: none; font-size: 14px; transition: color 0.15s; }
nav a:hover { color: #fff; }
nav .spacer { flex: 1; }
main { padding: 20px; max-width: 1200px; margin: 0 auto; }
@media (max-width: 640px) {
  main { padding: 12px; }
  nav { padding: 10px 12px; gap: 10px; }
}
table { border-collapse: collapse; width: 100%; background: #fff; }
th, td { border: 1px solid #e4e4e8; padding: 8px 10px; text-align: left; font-size: 14px; }
th { background: #f0f0f3; font-weight: 600; }
form.inline { display: inline; }
.card {
  background: #fff;
  border: 1px solid #e4e4e8;
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}
label { display: block; margin-top: 10px; font-size: 13px; color: #444; }
input, select, textarea {
  width: 100%;
  padding: 6px 8px;
  margin-top: 2px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 14px;
}
button, .btn {
  background: #1a1a2e;
  color: #fff;
  border: none;
  padding: 8px 14px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  margin-top: 12px;
}
button:hover, .btn:hover { background: #33335c; }
.error { color: #c0392b; margin-top: 8px; }
.kanban { display: flex; gap: 16px; align-items: flex-start; }
.kanban-col { flex: 1; background: #fff; border-radius: 6px; padding: 10px; }
.kanban-col h3 { margin-top: 0; font-size: 15px; }
.kanban-card {
  background: #fafafa;
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 10px;
  margin-bottom: 10px;
  font-size: 13px;
}
.kanban-card-info { cursor: pointer; }
.kanban-card-info:hover { opacity: 0.75; }

.period-presets { display: flex; gap: 8px; }
.period-presets .btn { margin-top: 0; text-decoration: none; display: inline-block; opacity: 0.6; }
.period-presets .btn.active { opacity: 1; }
.settlement-line { font-size: 20px; font-weight: 600; }
.badge { display: inline-block; padding: 2px 6px; border-radius: 3px; font-size: 12px; background: #eee; }
.balance-owe { color: #c0392b; font-weight: bold; }
.balance-owed { color: #27ae60; font-weight: bold; }

.toolbar { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.filters { display: flex; gap: 8px; }
.filters input, .filters select { width: auto; margin-top: 0; }
.filters button { margin-top: 0; }
.table-scroll { overflow-x: auto; background: #fff; border-radius: 6px; }
.sort-link { color: inherit; text-decoration: none; }
.sort-link:hover { text-decoration: underline; }
.col-narrow { width: 1%; white-space: nowrap; }
.order-row { cursor: pointer; }
.order-row:hover { background: #f0f2ff; }
.pay-status { font-weight: 600; white-space: nowrap; }
.pay-status.status-none { color: #c0392b; }
.pay-status.status-partial { color: #d68910; }
.pay-status.status-full { color: #27ae60; }

tr.overdue { box-shadow: inset 3px 0 0 #c0392b; }
.kanban-card.overdue { border-color: #c0392b; box-shadow: 0 0 0 1px #c0392b inset; }
.overdue-mark { color: #c0392b; }

.badge-cancelled { background: #ddd; color: #888; }
.kanban-card.cancelled { background: #eee; color: #999; opacity: 0.75; }
.kanban-card.cancelled strong { color: #999; }
.cancelled-section { margin-top: 20px; color: #666; }
.cancelled-section summary { cursor: pointer; font-size: 14px; padding: 8px 0; }
.cancelled-section .kanban { margin-top: 10px; }

.pagination { display: flex; align-items: center; gap: 12px; margin-top: 14px; justify-content: center; font-size: 13px; color: #555; }
.pagination .btn { margin-top: 0; }

.autocomplete-list { position: relative; }
.autocomplete-item {
  background: #fff;
  border: 1px solid #ddd;
  border-top: none;
  padding: 6px 8px;
  font-size: 13px;
  cursor: pointer;
}
.autocomplete-item:hover { background: #f0f2ff; }
.rs-note { color: #d68910; font-size: 13px; margin-top: 6px; }
#line-items-table input, #payments-table input, #line-items-table select, #payments-table select {
  width: 100%;
  margin-top: 0;
}

.kanban-comment-form { display: flex; gap: 6px; margin-top: 8px; }
.kanban-comment-form input { margin-top: 0; font-size: 12px; }
.kanban-comment-form button { margin-top: 0; padding: 6px 10px; font-size: 12px; }
#chat-widget-float { position: fixed; right: 20px; bottom: 20px; z-index: 90; }
#chat-toggle-btn {
  width: 56px; height: 56px; border-radius: 50%; border: none;
  background: #1a1a2e; color: #fff; font-size: 24px; cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3); position: relative;
}
.chat-unread-badge {
  position: absolute; top: -2px; right: -2px; background: #e11d48; color: #fff;
  border-radius: 999px; font-size: 11px; line-height: 1.4; padding: 1px 6px; min-width: 18px;
}
.chat-panel {
  position: fixed; right: 20px; bottom: 88px; width: 320px; max-height: 420px;
  background: #fff; border: 1px solid #e4e4e8; border-radius: 10px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2); flex-direction: column; overflow: hidden;
}
.chat-panel-header {
  background: #1a1a2e; color: #fff; padding: 10px 12px; display: flex;
  justify-content: space-between; align-items: center; font-weight: 600;
}
.chat-panel-close { background: none; border: none; color: #fff; font-size: 18px; cursor: pointer; line-height: 1; }
.chat-feed { flex: 1; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 6px; }
.chat-day-sep { text-align: center; color: #999; font-size: 11px; margin: 6px 0; }
.chat-msg { font-size: 13px; padding: 6px 10px; border-radius: 8px; background: #f0f0f0; max-width: 85%; }
.chat-msg-owner { align-self: flex-end; background: #dbeafe; }
.chat-msg-master { align-self: flex-start; background: #f0f0f0; }
.chat-msg-order { color: #888; font-size: 11px; display: block; }
.chat-widget-form { display: flex; gap: 6px; padding: 8px; border-top: 1px solid #e4e4e8; }
.chat-widget-form input { margin-top: 0; flex: 1; }
.chat-widget-form button { margin-top: 0; }
@media (max-width: 640px) {
  .chat-panel { width: calc(100vw - 32px); right: 16px; }
  #chat-widget-float { right: 16px; bottom: 16px; }
}

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  z-index: 100;
  overflow-y: auto;
}
.modal-box {
  background: #fff;
  border-radius: 8px;
  padding: 20px 24px;
  max-width: 520px;
  width: 100%;
  position: relative;
}
.modal-close {
  position: absolute;
  top: 10px;
  right: 14px;
  background: none;
  border: none;
  color: #888;
  font-size: 22px;
  cursor: pointer;
  margin: 0;
  padding: 0;
  line-height: 1;
}
.modal-close:hover { color: #1a1a1a; background: none; }
.modal-row { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; font-size: 14px; }
.modal-label { color: #666; }
.modal-value { font-weight: 600; text-align: right; }
.modal-calc .modal-row { font-size: 13px; }
