/* Myesa Central CRM — application styles on top of Bootstrap 5.3 */
:root {
  --crm-bg: #f3f4f6;
  --crm-surface: #ffffff;
  --crm-border: #e2e5ea;
  --crm-border-strong: #cfd4db;
  --crm-text: #1f2933;
  --crm-muted: #6b7480;
  --crm-primary: #1d4e89;
  --crm-primary-hover: #163d6c;
  --crm-primary-soft: #e8eef6;
  --crm-sidebar-w: 232px;
  --crm-sidebar-w-collapsed: 62px;
  --crm-topbar-h: 54px;
  --bs-body-font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --bs-body-font-size: .875rem;
  --bs-body-color: var(--crm-text);
  --bs-border-color: var(--crm-border);
  --bs-primary: var(--crm-primary);
  --bs-primary-rgb: 29, 78, 137;
  --bs-link-color: var(--crm-primary);
  --bs-link-color-rgb: 29, 78, 137;
  --bs-link-hover-color: var(--crm-primary-hover);
}
body { background: var(--crm-bg); }
a { text-decoration: none; }
a:hover { text-decoration: underline; }
.btn, .nav-link, .dropdown-item, .list-group-item-action, .page-link { text-decoration: none !important; }

.btn-primary { --bs-btn-bg: var(--crm-primary); --bs-btn-border-color: var(--crm-primary); --bs-btn-hover-bg: var(--crm-primary-hover); --bs-btn-hover-border-color: var(--crm-primary-hover); --bs-btn-active-bg: var(--crm-primary-hover); --bs-btn-disabled-bg: var(--crm-primary); --bs-btn-disabled-border-color: var(--crm-primary); }
.btn-outline-primary { --bs-btn-color: var(--crm-primary); --bs-btn-border-color: var(--crm-primary); --bs-btn-hover-bg: var(--crm-primary); --bs-btn-hover-border-color: var(--crm-primary); --bs-btn-active-bg: var(--crm-primary); }
.btn { --bs-btn-font-size: .8125rem; --bs-btn-padding-y: .32rem; --bs-btn-padding-x: .7rem; border-radius: 4px; }
.btn-sm { --bs-btn-font-size: .75rem; --bs-btn-padding-y: .2rem; --bs-btn-padding-x: .5rem; }
.btn-light { --bs-btn-bg: #fff; --bs-btn-border-color: var(--crm-border-strong); --bs-btn-hover-bg: #f6f7f9; --bs-btn-hover-border-color: var(--crm-border-strong); }
.form-control, .form-select { font-size: .8125rem; border-radius: 4px; border-color: var(--crm-border-strong); }
.form-control:focus, .form-select:focus { border-color: #6b8fbd; box-shadow: 0 0 0 .15rem rgba(29, 78, 137, .15); }
.form-label { font-weight: 500; font-size: .8rem; margin-bottom: .25rem; color: #3b4451; }
.form-text { font-size: .75rem; }
.required::after { content: " *"; color: #c0392b; }

/* ---------- Shell ---------- */
.crm-sidebar { position: fixed; top: 0; bottom: 0; left: 0; width: var(--crm-sidebar-w); background: var(--crm-surface); border-right: 1px solid var(--crm-border); display: flex; flex-direction: column; z-index: 1030; transition: width .15s; }
.crm-sidebar .brand-block { height: var(--crm-topbar-h); display: flex; align-items: center; gap: .6rem; padding: 0 1rem; border-bottom: 1px solid var(--crm-border); font-weight: 600; white-space: nowrap; overflow: hidden; }
.crm-sidebar .brand-mark { width: 30px; height: 30px; border-radius: 4px; background: var(--crm-primary); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-size: .8rem; flex-shrink: 0; }
.crm-nav { overflow-y: auto; flex: 1; padding: .5rem 0 1rem; }
.crm-nav .nav-section { font-size: .68rem; text-transform: uppercase; letter-spacing: .06em; color: #8a929d; padding: .9rem 1.1rem .3rem; white-space: nowrap; }
.crm-nav a { display: flex; align-items: center; gap: .7rem; padding: .42rem 1.1rem; color: #3b4451; white-space: nowrap; border-left: 3px solid transparent; }
.crm-nav a i { font-size: 1rem; width: 18px; text-align: center; color: #6b7480; flex-shrink: 0; }
.crm-nav a:hover { background: #f5f7fa; text-decoration: none; }
.crm-nav a.active { background: var(--crm-primary-soft); color: var(--crm-primary); border-left-color: var(--crm-primary); font-weight: 500; }
.crm-nav a.active i { color: var(--crm-primary); }
.crm-main { margin-left: var(--crm-sidebar-w); min-height: 100vh; transition: margin-left .15s; }
.crm-topbar { height: var(--crm-topbar-h); background: var(--crm-surface); border-bottom: 1px solid var(--crm-border); display: flex; align-items: center; gap: .75rem; padding: 0 1.25rem; position: sticky; top: 0; z-index: 1020; }
.crm-topbar .search { max-width: 360px; flex: 1; }
.crm-topbar .search .form-control { background: #f5f6f8; border-color: transparent; padding-left: 2rem; }
.crm-topbar .search i { position: absolute; left: .65rem; top: 50%; transform: translateY(-50%); color: #8a929d; }
.crm-content { padding: 1.25rem; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: #dfe6ef; color: var(--crm-primary); font-size: .72rem; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.avatar-sm { width: 24px; height: 24px; font-size: .62rem; }

body.sidebar-collapsed .crm-sidebar { width: var(--crm-sidebar-w-collapsed); }
body.sidebar-collapsed .crm-main { margin-left: var(--crm-sidebar-w-collapsed); }
body.sidebar-collapsed .crm-nav .nav-section, body.sidebar-collapsed .crm-nav a span, body.sidebar-collapsed .brand-block .brand-name { display: none; }
body.sidebar-collapsed .crm-nav a { justify-content: center; padding-left: 0; padding-right: 0; }

@media (max-width: 991.98px) {
  .crm-sidebar { transform: translateX(-100%); transition: transform .15s; width: var(--crm-sidebar-w) !important; }
  body.sidebar-open .crm-sidebar { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.25); }
  .crm-main { margin-left: 0 !important; }
  body.sidebar-collapsed .crm-nav .nav-section, body.sidebar-collapsed .crm-nav a span { display: initial; }
  .crm-content { padding: .9rem; }
}

/* ---------- Page pieces ---------- */
.page-header { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: .75rem; margin-bottom: 1rem; }
.page-header h1 { font-size: 1.2rem; font-weight: 600; margin: 0; }
.page-header .sub { color: var(--crm-muted); font-size: .8rem; margin-top: .15rem; }
.breadcrumb { font-size: .75rem; margin-bottom: .2rem; }
.panel { background: var(--crm-surface); border: 1px solid var(--crm-border); border-radius: 6px; }
.panel + .panel { margin-top: 1rem; }
.panel-header { padding: .7rem 1rem; border-bottom: 1px solid var(--crm-border); display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.panel-header h2, .panel-header h3 { font-size: .9rem; font-weight: 600; margin: 0; }
.panel-body { padding: 1rem; }
.panel-footer { padding: .6rem 1rem; border-top: 1px solid var(--crm-border); background: #fafbfc; border-radius: 0 0 6px 6px; }

.stat { padding: .85rem 1rem; }
.stat .label { color: var(--crm-muted); font-size: .75rem; }
.stat .value { font-size: 1.25rem; font-weight: 600; margin-top: .15rem; }
.stat .meta { font-size: .72rem; color: var(--crm-muted); }
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.stat-row > .stat + .stat { border-left: 1px solid var(--crm-border); }
@media (max-width: 575.98px) { .stat-row > .stat + .stat { border-left: 0; border-top: 1px solid var(--crm-border); } }

.filter-bar { display: flex; flex-wrap: wrap; gap: .5rem; padding: .7rem 1rem; border-bottom: 1px solid var(--crm-border); align-items: center; }
.filter-bar .form-control, .filter-bar .form-select { width: auto; min-width: 140px; }
.filter-bar .grow { flex: 1; min-width: 180px; }

.table { --bs-table-bg: transparent; margin: 0; font-size: .8125rem; }
.table > thead th { font-size: .72rem; text-transform: uppercase; letter-spacing: .03em; color: #5f6873; font-weight: 600; background: #f8f9fb; border-bottom: 1px solid var(--crm-border); white-space: nowrap; padding: .55rem .75rem; }
.table > tbody td { padding: .55rem .75rem; vertical-align: middle; border-color: #eef0f3; }
.table-hover > tbody > tr:hover > * { --bs-table-bg-state: #f7f9fc; }
.table .num, .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table a.row-title { font-weight: 500; color: var(--crm-text); }
.table a.row-title:hover { color: var(--crm-primary); }
.table-responsive { border-radius: 0 0 6px 6px; }
.text-muted-2 { color: var(--crm-muted) !important; }
.small-2 { font-size: .75rem; }

.badge-status { display: inline-block; padding: .18rem .5rem; border-radius: 3px; font-size: .7rem; font-weight: 600; border: 1px solid transparent; white-space: nowrap; }
.st-gray { background: #f1f3f5; color: #545c66; border-color: #e2e5ea; }
.st-blue { background: #e7f0fa; color: #1d5797; border-color: #cfe0f3; }
.st-green { background: #e6f4ea; color: #1e6b37; border-color: #cbe7d3; }
.st-amber { background: #fdf3e1; color: #8a5a00; border-color: #f5e0b5; }
.st-red { background: #fbe9e9; color: #a12a2a; border-color: #f2cfcf; }
.st-purple { background: #f0ebf8; color: #5b3d8f; border-color: #e0d6f0; }
.brand-dot { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: .35rem; vertical-align: middle; }
.brand-tag { font-size: .72rem; color: #4a525c; white-space: nowrap; }

.detail-list { display: grid; grid-template-columns: 140px 1fr; gap: .45rem .75rem; margin: 0; font-size: .8125rem; }
.detail-list dt { color: var(--crm-muted); font-weight: 400; }
.detail-list dd { margin: 0; word-break: break-word; }

.nav-tabs { border-bottom-color: var(--crm-border); padding: 0 1rem; }
.nav-tabs .nav-link { color: #59616b; font-size: .8125rem; border: 0; border-bottom: 2px solid transparent; padding: .65rem .2rem; margin-right: 1.1rem; border-radius: 0; }
.nav-tabs .nav-link.active { color: var(--crm-primary); border-bottom-color: var(--crm-primary); background: none; font-weight: 500; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 .9rem 1.2rem; font-size: .8rem; }
.timeline li::before { content: ""; position: absolute; left: 3px; top: 6px; width: 7px; height: 7px; border-radius: 50%; background: #9aa5b1; }
.timeline li::after { content: ""; position: absolute; left: 6px; top: 16px; bottom: 0; width: 1px; background: var(--crm-border); }
.timeline li:last-child::after { display: none; }
.timeline .when { color: var(--crm-muted); font-size: .72rem; }

.note-item { border-bottom: 1px solid #eef0f3; padding: .7rem 0; }
.note-item:last-child { border-bottom: 0; }
.empty-state { text-align: center; color: var(--crm-muted); padding: 2.2rem 1rem; font-size: .8125rem; }
.empty-state i { font-size: 1.6rem; display: block; margin-bottom: .4rem; color: #b5bcc5; }

.items-table td { vertical-align: top; }
.items-table .form-control, .items-table .form-select { font-size: .8rem; }
.totals-table td { padding: .3rem .5rem; }
.totals-table tr.grand td { font-weight: 600; font-size: .95rem; border-top: 1px solid var(--crm-border-strong); }

.kanban { display: flex; gap: .75rem; overflow-x: auto; padding-bottom: .5rem; }
.kanban-col { flex: 0 0 270px; background: #eceef2; border-radius: 6px; padding: .5rem; max-height: 75vh; display: flex; flex-direction: column; }
.kanban-col h4 { font-size: .78rem; font-weight: 600; margin: .2rem .3rem .5rem; display: flex; justify-content: space-between; }
.kanban-cards { overflow-y: auto; }
.kanban-card { background: #fff; border: 1px solid var(--crm-border); border-radius: 4px; padding: .55rem .65rem; margin-bottom: .45rem; font-size: .78rem; }
.kanban-card .title { font-weight: 500; color: var(--crm-text); }

.progress { height: 6px; border-radius: 3px; background: #e9ecef; }
.progress-bar { background: var(--crm-primary); }
.settings-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: .75rem; }
.settings-grid a { display: flex; gap: .75rem; padding: .85rem 1rem; color: var(--crm-text); }
.settings-grid a:hover { background: #f8fafc; text-decoration: none; }
.settings-grid a i { font-size: 1.15rem; color: var(--crm-primary); margin-top: .1rem; }
.settings-grid .t { font-weight: 500; }
.settings-grid .d { font-size: .75rem; color: var(--crm-muted); }
.settings-nav a { display: block; padding: .4rem .9rem; color: #3b4451; border-left: 3px solid transparent; font-size: .8125rem; }
.settings-nav a.active { border-left-color: var(--crm-primary); background: var(--crm-primary-soft); color: var(--crm-primary); }
.code-var { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .72rem; background: #f1f3f5; border: 1px solid #e2e5ea; padding: .05rem .3rem; border-radius: 3px; cursor: pointer; }
.alert { font-size: .8125rem; border-radius: 4px; }
.dropdown-menu { font-size: .8125rem; border-color: var(--crm-border); box-shadow: 0 4px 14px rgba(15, 23, 42, .08); }
.notif-dot { position: absolute; top: 2px; right: 0; min-width: 16px; height: 16px; border-radius: 8px; font-size: .62rem; background: #c0392b; color: #fff; display: flex; align-items: center; justify-content: center; padding: 0 3px; }
.pagination { --bs-pagination-font-size: .78rem; margin: 0; }
.list-footer { display: flex; justify-content: space-between; align-items: center; padding: .6rem 1rem; border-top: 1px solid var(--crm-border); font-size: .75rem; color: var(--crm-muted); flex-wrap: wrap; gap: .5rem; }
.list-footer nav p { display: none; }
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.auth-box { width: 100%; max-width: 380px; }
.overdue { color: #b42318 !important; }
@media print { .crm-sidebar, .crm-topbar, .no-print { display: none !important; } .crm-main { margin: 0; } }
