/* ==========================================================================
   Temple CRM — brand layer over Bootstrap 5.3
   Bootstrap 5.3 exposes component CSS variables, so the brand is applied by
   overriding those rather than recompiling Sass. Loads AFTER bootstrap.min.css.
   ========================================================================== */

:root {
    --tm-deep: #40101C;
    --tm-deep-2: #2E0B14;
    --tm-deep-3: #55202D;
    --tm-brass: #B0812F;
    --tm-brass-soft: #D9BE84;
    --tm-saffron: #DE6B1F;
    --tm-saffron-dark: #BE560F;
    --tm-paper: #F1EEE8;
    --tm-surface: #FFFFFF;
    --tm-ink: #24191C;
    --tm-ink-soft: #6B5D62;
    --tm-line: #E2DCD2;

    --tm-sidebar-w: 264px;
    --tm-topbar-h: 60px;

    /* Bootstrap global overrides */
    --bs-body-font-family: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --bs-body-font-size: 0.9375rem;
    --bs-body-color: var(--tm-ink);
    --bs-body-bg: var(--tm-paper);
    --bs-border-color: var(--tm-line);
    --bs-primary: var(--tm-saffron);
    --bs-primary-rgb: 222, 107, 31;
    --bs-link-color: var(--tm-saffron-dark);
    --bs-link-hover-color: var(--tm-deep);
    --bs-focus-ring-color: rgba(222, 107, 31, .3);
    --bs-border-radius: .375rem;
}

body {
    background: var(--tm-paper);
    font-feature-settings: "tnum" 1;
}

/* Money and counts must align down a column. */
.tabular { font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */
.btn-primary {
    --bs-btn-bg: var(--tm-saffron);
    --bs-btn-border-color: var(--tm-saffron);
    --bs-btn-hover-bg: var(--tm-saffron-dark);
    --bs-btn-hover-border-color: var(--tm-saffron-dark);
    --bs-btn-active-bg: var(--tm-saffron-dark);
    --bs-btn-active-border-color: var(--tm-saffron-dark);
    --bs-btn-disabled-bg: var(--tm-saffron);
    --bs-btn-disabled-border-color: var(--tm-saffron);
}

.btn-outline-secondary {
    --bs-btn-color: var(--tm-ink-soft);
    --bs-btn-border-color: var(--tm-line);
    --bs-btn-hover-bg: var(--tm-paper);
    --bs-btn-hover-color: var(--tm-ink);
    --bs-btn-hover-border-color: var(--tm-brass-soft);
}

.btn-deep {
    --bs-btn-color: #fff;
    --bs-btn-bg: var(--tm-deep);
    --bs-btn-border-color: var(--tm-deep);
    --bs-btn-hover-color: #fff;
    --bs-btn-hover-bg: var(--tm-deep-2);
    --bs-btn-hover-border-color: var(--tm-deep-2);
}

/* --------------------------------------------------------------------------
   Sidebar
   -------------------------------------------------------------------------- */
.tm-sidebar {
    background: var(--tm-deep);
    color: rgba(255, 255, 255, .82);
    width: var(--tm-sidebar-w);
    display: flex;
    flex-direction: column;
}

.tm-sidebar__brand {
    height: var(--tm-topbar-h);
    display: flex;
    align-items: center;
    gap: .625rem;
    padding: 0 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, .09);
    flex: 0 0 auto;
}

.tm-sidebar__mark {
    width: 32px;
    height: 32px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    border: 1px solid var(--tm-brass);
    color: var(--tm-brass-soft);
    font-size: 1rem;
    flex: 0 0 auto;
}

/* The one deliberately expressive element in the whole interface. */
.tm-sidebar__wordmark {
    font-family: "IBM Plex Serif", Georgia, serif;
    font-size: 1.0625rem;
    font-weight: 500;
    letter-spacing: .01em;
    color: #fff;
    line-height: 1.15;
    margin: 0;
}

.tm-sidebar__sub {
    font-size: .6875rem;
    color: var(--tm-brass-soft);
    line-height: 1.1;
}

.tm-sidebar__nav {
    overflow-y: auto;
    padding: .5rem 0 1rem;
    flex: 1 1 auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, .22) transparent;
}

.tm-sidebar__nav::-webkit-scrollbar { width: 6px; }
.tm-sidebar__nav::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, .2);
    border-radius: 3px;
}

.tm-sidebar__heading {
    font-size: .6875rem;
    font-weight: 500;
    color: rgba(217, 190, 132, .78);
    padding: 1rem 1rem .25rem 1.125rem;
    margin: 0;
}

.tm-nav-link {
    display: flex;
    align-items: center;
    gap: .625rem;
    padding: .5rem 1rem .5rem 1.125rem;
    color: rgba(255, 255, 255, .78);
    text-decoration: none;
    font-size: .875rem;
    border-left: 3px solid transparent;
    transition: background-color .12s ease, color .12s ease;
}

.tm-nav-link i { font-size: 1rem; width: 1.125rem; flex: 0 0 auto; }

.tm-nav-link:hover,
.tm-nav-link:focus-visible {
    background: var(--tm-deep-3);
    color: #fff;
}

/* Brass rail encodes position in the tree, not decoration. */
.tm-nav-link.is-active {
    background: var(--tm-deep-2);
    border-left-color: var(--tm-brass);
    color: #fff;
    font-weight: 500;
}

.tm-nav-link .badge-soon {
    margin-left: auto;
    font-size: .5625rem;
    color: var(--tm-brass-soft);
    border: 1px solid rgba(217, 190, 132, .35);
    border-radius: 2rem;
    padding: 0 .375rem;
    line-height: 1.35;
}

.tm-sidebar__foot {
    border-top: 1px solid rgba(255, 255, 255, .09);
    padding: .75rem 1rem;
    font-size: .75rem;
    color: rgba(255, 255, 255, .55);
    flex: 0 0 auto;
}

/* --------------------------------------------------------------------------
   Shell
   -------------------------------------------------------------------------- */
.tm-topbar {
    height: var(--tm-topbar-h);
    background: var(--tm-surface);
    border-bottom: 1px solid var(--tm-line);
    position: sticky;
    top: 0;
    z-index: 1020;
}

.tm-main { min-height: 100vh; }
.tm-content { padding: 1.5rem 1.25rem 3rem; }

@media (min-width: 992px) {
    .tm-sidebar-fixed {
        position: fixed;
        inset: 0 auto 0 0;
        z-index: 1030;
    }
    .tm-main { margin-left: var(--tm-sidebar-w); }
    .tm-content { padding: 1.75rem 1.75rem 3rem; }

    /* Collapsed rail: icons only, toggled from the topbar. */
    body.tm-collapsed { --tm-sidebar-w: 68px; }
    body.tm-collapsed .tm-sidebar__wordmark,
    body.tm-collapsed .tm-sidebar__sub,
    body.tm-collapsed .tm-sidebar__heading,
    body.tm-collapsed .tm-nav-link span,
    body.tm-collapsed .tm-sidebar__foot,
    body.tm-collapsed .badge-soon { display: none; }
    body.tm-collapsed .tm-nav-link { justify-content: center; padding-left: 0; padding-right: 0; }
    body.tm-collapsed .tm-sidebar__brand { justify-content: center; padding: 0; }
}

.tm-offcanvas { width: var(--tm-sidebar-w); }
.tm-offcanvas .tm-sidebar { height: 100%; width: 100%; }

/* --------------------------------------------------------------------------
   Page header + panels
   -------------------------------------------------------------------------- */
.tm-page-title {
    font-size: 1.375rem;
    font-weight: 600;
    letter-spacing: -.01em;
    margin: 0;
}

.tm-page-sub { color: var(--tm-ink-soft); font-size: .875rem; margin: .125rem 0 0; }

.tm-panel {
    background: var(--tm-surface);
    border: 1px solid var(--tm-line);
    border-radius: .5rem;
}

.tm-panel__head {
    padding: .875rem 1rem;
    border-bottom: 1px solid var(--tm-line);
}

.tm-panel__body { padding: 1rem; }

/* Stat tiles: hairline rule, no shadow, no gradient. */
.tm-stat {
    background: var(--tm-surface);
    border: 1px solid var(--tm-line);
    border-top: 2px solid var(--tm-brass);
    border-radius: .5rem;
    padding: .875rem 1rem;
    height: 100%;
}

.tm-stat__value {
    font-size: 1.75rem;
    font-weight: 600;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}

.tm-stat__label { color: var(--tm-ink-soft); font-size: .8125rem; margin-top: .125rem; }
.tm-stat__meta { color: var(--tm-ink-soft); font-size: .75rem; margin-top: .5rem; }

/* --------------------------------------------------------------------------
   Tables
   -------------------------------------------------------------------------- */
.tm-table { --bs-table-bg: transparent; margin: 0; }

.tm-table thead th {
    font-size: .75rem;
    font-weight: 600;
    color: var(--tm-ink-soft);
    background: #FAF8F5;
    border-bottom: 1px solid var(--tm-line);
    white-space: nowrap;
    padding: .625rem .75rem;
}

.tm-table tbody td {
    padding: .6875rem .75rem;
    vertical-align: middle;
    border-bottom: 1px solid var(--tm-line);
}

.tm-table tbody tr:last-child td { border-bottom: 0; }
.tm-table tbody tr:hover { background: #FBF9F6; }

.tm-avatar {
    width: 32px; height: 32px;
    border-radius: 50%;
    display: grid; place-items: center;
    background: var(--tm-deep);
    color: var(--tm-brass-soft);
    font-size: .75rem; font-weight: 600;
    flex: 0 0 auto;
    object-fit: cover;
    overflow: hidden;
}

.tm-avatar img { width: 100%; height: 100%; object-fit: cover; }

.tm-pill {
    font-size: .6875rem;
    font-weight: 500;
    padding: .1875rem .5rem;
    border-radius: 2rem;
    border: 1px solid transparent;
    display: inline-block;
}

.tm-pill--active { background: #E8F3EC; color: #1E6B3F; border-color: #C6E2D1; }
.tm-pill--inactive { background: #F0EDE9; color: #6B5D62; border-color: var(--tm-line); }
.tm-pill--suspended { background: #FBEAE6; color: #A33417; border-color: #F1CFC6; }
.tm-pill--muted { background: var(--tm-paper); color: var(--tm-ink-soft); border-color: var(--tm-line); }

/* --------------------------------------------------------------------------
   Forms, empty and loading states
   -------------------------------------------------------------------------- */
.form-label { font-size: .8125rem; font-weight: 500; margin-bottom: .25rem; }
.form-control, .form-select { font-size: .875rem; }
.form-control:focus, .form-select:focus {
    border-color: var(--tm-brass-soft);
    box-shadow: 0 0 0 .2rem var(--bs-focus-ring-color);
}

.form-check-input:checked {
    background-color: var(--tm-saffron);
    border-color: var(--tm-saffron);
}

.tm-empty { padding: 2.5rem 1rem; text-align: center; color: var(--tm-ink-soft); }
.tm-empty i { font-size: 1.75rem; color: var(--tm-brass-soft); display: block; margin-bottom: .5rem; }

.tm-loading { padding: 2.5rem 1rem; text-align: center; color: var(--tm-ink-soft); }

.tm-perm-grid { max-height: 24rem; overflow-y: auto; }
.tm-perm-module { border-bottom: 1px solid var(--tm-line); padding: .625rem .25rem; }
.tm-perm-module:last-child { border-bottom: 0; }

/* Auth screens */
.tm-auth {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1.5rem;
    background:
        radial-gradient(1200px 420px at 50% -10%, rgba(64, 16, 28, .10), transparent 70%),
        var(--tm-paper);
}

.tm-auth__card {
    width: 100%;
    max-width: 27rem;
    background: var(--tm-surface);
    border: 1px solid var(--tm-line);
    border-top: 3px solid var(--tm-brass);
    border-radius: .625rem;
    padding: 1.75rem;
}

.tm-auth__title {
    font-family: "IBM Plex Serif", Georgia, serif;
    font-size: 1.375rem;
    font-weight: 500;
    margin: 0;
}

/* --------------------------------------------------------------------------
   Accessibility
   -------------------------------------------------------------------------- */
:focus-visible { outline: 2px solid var(--tm-saffron); outline-offset: 2px; }

.tm-skip-link {
    position: absolute; left: -999px; top: .5rem; z-index: 2000;
    background: var(--tm-surface); padding: .5rem .75rem; border-radius: .25rem;
}
.tm-skip-link:focus { left: .5rem; }

@media (prefers-reduced-motion: reduce) {
    * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

@media print {
    .tm-sidebar, .tm-topbar, .tm-no-print { display: none !important; }
    .tm-main { margin-left: 0; }
    .tm-panel { border: 0; }
}

/* ==========================================================================
   Full-page create / edit forms
   Create and edit moved out of modals and onto their own pages, so they need
   the chrome a dialog used to provide: grouping, and a save bar that stays
   reachable on a long form.
   ========================================================================== */
.tm-form{max-width:920px;}
.tm-form .tm-panel{margin-bottom:18px;}
.tm-form .tm-panel__head{font-weight:600; color:var(--tm-maroon, #7A1F2B);}

.tm-fieldset{padding:22px 24px;}
.tm-fieldset + .tm-fieldset{border-top:1px solid rgba(122,31,43,0.08);}
.tm-fieldset__legend{
  font-size:12px; font-weight:700; letter-spacing:0.08em; text-transform:uppercase;
  color:#6B5D62; margin-bottom:16px; display:flex; align-items:center; gap:8px;
}
.tm-fieldset__legend .num{
  width:20px; height:20px; border-radius:50%; flex-shrink:0;
  background:rgba(222,107,31,0.14); color:#C9622A;
  display:flex; align-items:center; justify-content:center; font-size:11px;
}

.tm-form-actions{
  position:sticky; bottom:0; z-index:10;
  display:flex; align-items:center; justify-content:space-between; gap:16px;
  flex-wrap:wrap;
  background:rgba(253,247,238,0.94);
  backdrop-filter:blur(8px); -webkit-backdrop-filter:blur(8px);
  border-top:1px solid rgba(122,31,43,0.12);
  padding:14px 4px; margin-top:8px;
}

/* A read-only value shown beside the inputs, e.g. a generated code. */
.tm-static-value{
  display:block; padding:8px 0; font-weight:600; color:#2B1B14;
  font-variant-numeric:tabular-nums;
}

@media (max-width:600px){
  .tm-fieldset{padding:18px 16px;}
  .tm-form-actions{flex-direction:column-reverse; align-items:stretch;}
  .tm-form-actions > div{width:100%;}
  .tm-form-actions .btn{width:100%;}
}
