/* ============================================================
   Commission Settlement ERP - Stylesheet
   ============================================================ */

:root {
  --c-primary: #1d4ed8;
  --c-primary-dark: #1e40af;
  --c-success: #16a34a;
  --c-info: #0ea5e9;
  --c-warn: #f59e0b;
  --c-danger: #dc2626;
  --c-bg: #f3f4f6;
  --c-surface: #ffffff;
  --c-border: #e5e7eb;
  --c-text: #1f2937;
  --c-muted: #6b7280;
  --c-sidebar-bg: #0f172a;
  --c-sidebar-fg: #cbd5e1;
  --c-sidebar-active: #1d4ed8;
  --c-topbar-bg: #ffffff;
  --c-card-shadow: 0 1px 2px rgba(0,0,0,.05), 0 1px 1px rgba(0,0,0,.04);
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Inter, Arial, sans-serif;
  background: var(--c-bg);
  color: var(--c-text);
  font-size: 14px;
  margin: 0;
}

/* ------------------------------------------------------------ Auth pages */
.auth-body {
  background: linear-gradient(135deg, #1e3a8a 0%, #1d4ed8 35%, #2563eb 70%, #38bdf8 100%);
  min-height: 100vh;
}
.auth-body-client {
  background: linear-gradient(135deg, #064e3b 0%, #047857 35%, #059669 70%, #10b981 100%);
}
.auth-wrap {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.auth-card {
  background: var(--c-surface);
  border-radius: 14px;
  width: 100%; max-width: 420px;
  padding: 32px 28px 24px;
}
.auth-brand { text-align: center; margin-bottom: 22px; }
.brand-logo {
  width: 64px; height: 64px; border-radius: 16px;
  background: linear-gradient(135deg, #1d4ed8, #38bdf8);
  color: #fff; font-size: 32px; line-height: 64px;
  margin: 0 auto 12px;
}
.brand-logo-client { background: linear-gradient(135deg, #047857, #10b981); }

/* ------------------------------------------------------------ App shell */
.app-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}
.app-main { display: flex; flex-direction: column; min-width: 0; }

/* sidebar */
.app-sidebar {
  background: var(--c-sidebar-bg);
  color: var(--c-sidebar-fg);
  padding: 18px 12px 16px;
  position: sticky; top: 0;
  height: 100vh; overflow-y: auto;
}
.sb-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 6px 16px;
  border-bottom: 1px solid #1e293b;
  margin-bottom: 14px;
}
.sb-logo {
  width: 38px; height: 38px; border-radius: 10px;
  background: linear-gradient(135deg,#1d4ed8,#38bdf8);
  color: #fff; font-size: 20px;
  display: flex; align-items: center; justify-content: center;
}
.sb-title { color: #f1f5f9; font-weight: 600; font-size: 13px; line-height: 1.2; }
.sb-sub   { color: #64748b; font-size: 11px; }

.sb-group {
  text-transform: uppercase; font-size: 10.5px; letter-spacing: .08em;
  color: #64748b; padding: 14px 10px 6px;
}
.sb-nav { display: flex; flex-direction: column; }
.sb-link {
  color: var(--c-sidebar-fg);
  padding: 9px 12px; margin-bottom: 2px;
  border-radius: 8px; text-decoration: none;
  font-size: 13px;
  display: flex; align-items: center; gap: 10px;
  transition: background .15s, color .15s;
}
.sb-link i { width: 16px; text-align: center; opacity: .85; }
.sb-link:hover { background: #111827; color: #ffffff; }
.sb-link.active {
  background: var(--c-sidebar-active);
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(29,78,216,.4);
}
.sidebar-client .sb-link.active { background: #047857; box-shadow: 0 2px 6px rgba(4,120,87,.4); }

/* topbar */
.app-topbar {
  display: flex; align-items: center;
  background: var(--c-topbar-bg);
  padding: 10px 18px;
  border-bottom: 1px solid var(--c-border);
  min-height: 56px;
}
.topbar-title strong { font-size: 16px; }

/* content */
.app-content { padding: 22px; flex: 1; }
.app-footer {
  padding: 12px 18px;
  border-top: 1px solid var(--c-border);
  background: var(--c-surface);
  display: flex; align-items: center;
  font-size: 12px; color: var(--c-muted);
}

/* responsive: collapse sidebar */
@media (max-width: 880px) {
  .app-shell { grid-template-columns: 1fr; }
  .app-sidebar {
    position: fixed; left: -260px; top: 0; bottom: 0;
    width: 240px; z-index: 1040; transition: left .25s ease;
    box-shadow: 4px 0 12px rgba(0,0,0,.18);
  }
  .app-sidebar.open { left: 0; }
  .app-content { padding: 14px; }
}

/* ------------------------------------------------------------ Cards */
.card { border: 1px solid var(--c-border); border-radius: var(--radius); box-shadow: var(--c-card-shadow); }
.card .card-header {
  background: #fafafa; font-weight: 600;
  border-bottom: 1px solid var(--c-border);
  padding: 11px 16px;
}
.stat-card {
  background: #fff; border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 16px; position: relative; overflow: hidden;
  box-shadow: var(--c-card-shadow);
}
.stat-card .lbl { color: var(--c-muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.stat-card .val { font-size: 22px; font-weight: 700; margin-top: 4px; color: var(--c-text); }
.stat-card .ico {
  position: absolute; right: 12px; top: 12px;
  width: 40px; height: 40px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center; font-size: 20px;
  color: #fff;
}
.stat-card.primary .ico { background: var(--c-primary); }
.stat-card.success .ico { background: var(--c-success); }
.stat-card.info    .ico { background: var(--c-info); }
.stat-card.warn    .ico { background: var(--c-warn); }
.stat-card.danger  .ico { background: var(--c-danger); }
.stat-card.dark    .ico { background: #334155; }

/* table */
.table-app { font-size: 13px; }
.table-app thead th {
  background: #f8fafc; color: #334155;
  border-bottom: 1px solid #e2e8f0 !important;
  font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em;
  vertical-align: middle;
}
.table-app td { vertical-align: middle; }
.table-app tbody tr:hover { background: #fafbff; }
.table-tight td, .table-tight th { padding: 7px 10px; }

.amt { font-family: 'Segoe UI', Inter, system-ui, sans-serif; font-variant-numeric: tabular-nums; }
.amt-cr { color: var(--c-success); font-weight: 600; }
.amt-dr { color: var(--c-danger); font-weight: 600; }

.badge-mode {
  display: inline-block; font-size: 10.5px; letter-spacing: .04em;
  padding: 2px 8px; border-radius: 12px; font-weight: 600;
}
.badge-mode.CASH { background: #ecfdf5; color: #047857; }
.badge-mode.BANK { background: #eff6ff; color: #1d4ed8; }
.badge-mode.ACTIVE { background: #ecfdf5; color: #047857; }
.badge-mode.CANCELLED { background: #fef2f2; color: #b91c1c; }
.badge-mode.PENDING { background: #fef3c7; color: #92400e; }
.badge-mode.REJECTED { background: #f3f4f6; color: #4b5563; }

.filter-bar {
  background: #fff; border: 1px solid var(--c-border);
  border-radius: var(--radius); padding: 12px; margin-bottom: 14px;
}
.filter-bar .form-label { font-size: 11.5px; color: var(--c-muted); text-transform: uppercase; letter-spacing: .03em; margin-bottom: 2px; }
.filter-bar .form-control, .filter-bar .form-select { font-size: 13px; }

.page-actions {
  display: flex; justify-content: space-between;
  align-items: center; gap: 8px; flex-wrap: wrap;
  margin-bottom: 14px;
}
.page-actions h5 { margin: 0; font-weight: 700; }

.btn-app-primary { background: var(--c-primary); color: #fff; border: 0; }
.btn-app-primary:hover { background: var(--c-primary-dark); color: #fff; }

/* form */
.form-card label.form-label { font-size: 12px; color: #374151; font-weight: 500; }
.form-card .form-control, .form-card .form-select { font-size: 13px; }
.form-card .required::after { content: " *"; color: var(--c-danger); }

/* voucher header */
.voucher-head {
  background: linear-gradient(135deg, #1e3a8a, #1d4ed8); color: #fff;
  border-radius: var(--radius); padding: 16px 18px; margin-bottom: 14px;
}
.voucher-head .v-no { font-size: 22px; font-weight: 700; }
.voucher-head .v-meta { opacity: .9; font-size: 13px; }

/* print */
@media print {
  .app-sidebar, .app-topbar, .app-footer, .no-print, .btn, .filter-bar { display: none !important; }
  .app-shell { grid-template-columns: 1fr; }
  .app-content { padding: 0; }
  body { background: #fff; font-size: 11pt; }
  .card { border: 1px solid #ddd; box-shadow: none; }
  .table-app thead th { background: #f0f0f0 !important; }
}

/* ------------------------------------------------------------ Chat */
.chat-card {
  display: flex; flex-direction: column;
  height: calc(100vh - 220px);
  min-height: 420px;
  overflow: hidden;
}
.chat-body {
  flex: 1; overflow-y: auto;
  padding: 16px;
  background: #f9fafb;
  display: flex; flex-direction: column; gap: 8px;
}
.chat-msg { display: flex; }
.chat-msg.mine { justify-content: flex-end; }
.chat-msg.theirs { justify-content: flex-start; }
.chat-bubble {
  max-width: 70%;
  padding: 8px 12px;
  border-radius: 14px;
  word-wrap: break-word;
  box-shadow: 0 1px 2px rgba(0,0,0,.06);
  font-size: 13.5px;
  line-height: 1.4;
}
.chat-msg.mine .chat-bubble {
  background: #1d4ed8; color: #fff;
  border-bottom-right-radius: 4px;
}
.chat-msg.theirs .chat-bubble {
  background: #fff; color: #1f2937;
  border: 1px solid #e5e7eb;
  border-bottom-left-radius: 4px;
}
.chat-text { white-space: pre-wrap; }
.chat-time { font-size: 10.5px; opacity: .75; margin-top: 3px; text-align: right; }
.chat-msg.theirs .chat-time { color: #6b7280; }
.chat-compose {
  display: flex; gap: 8px;
  padding: 10px 12px;
  background: #fff;
  border-top: 1px solid var(--c-border);
}
.chat-compose textarea { flex: 1; resize: none; border-radius: 10px; font-size: 14px; min-height: 38px; max-height: 120px; }
.chat-compose button { padding: 0 16px; border-radius: 10px; }
/* client portal: own messages in green */
.sidebar-client ~ .app-main .chat-msg.mine .chat-bubble,
.app-shell:has(.sidebar-client) .chat-msg.mine .chat-bubble {
  background: #047857;
}

/* misc utility */
.cursor-pointer { cursor: pointer; }
.text-money { font-family: 'Segoe UI', Inter, system-ui, sans-serif; font-variant-numeric: tabular-nums; }
.text-truncate-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.chip { display: inline-block; padding: 2px 8px; background: #eef2ff; color: #4338ca; border-radius: 999px; font-size: 11px; }
