/* Main Layout */
body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    padding-top: 60px; /* Account for fixed navbar */
}

main {
    flex: 1;
    padding: 2rem 0;
}

/* Navbar Styles */
.navbar {
    background-color: #f8f9fa;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    padding: 0.5rem 0;
}

.navbar-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0;
}

.navbar-brand img {
    width: 50px;
    height: 50px;
}

.navbar-nav {
    gap: 0.5rem;
}

/* Dropdown menu styles */
.dropdown-menu {
    padding: 0.5rem 0;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    border: 1px solid rgba(0,0,0,0.1);
    min-width: 200px;
}

/* Phone numbers dropdown specific styles */
#phoneDropdown + .dropdown-menu {
    max-height: 400px;
    overflow-y: auto;
}

.dropdown-item {
    padding: 0.5rem 1rem;
    color: #333;
    white-space: normal;
}

.dropdown-item:hover {
    background-color: #f8f9fa;
    color: #0d6efd;
}

/* Phone number dropdown specific styles */
.dropdown-item span.fw-bold {
    display: block;
    margin-bottom: 0.25rem;
}

.dropdown-item small.text-muted {
    display: block;
    font-family: monospace;
}

.dropdown-divider {
    margin: 0.25rem 0;
}

/* Phone number menu item style */
.phone-menu-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.phone-menu-item .title {
    font-weight: bold;
    margin: 0;
}

.phone-menu-item .number {
    font-family: monospace;
    color: #666;
}

/* Sort arrows */
.sortable {
    cursor: pointer;
    position: relative;
    padding-right: 1.5rem;
}

.sortable:before,
.sortable:after {
    content: '';
    position: absolute;
    right: 4px;
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
}

.sortable:before {
    top: 40%;
    border-bottom: 6px solid #ccc;
}

.sortable:after {
    bottom: 40%;
    border-top: 6px solid #ccc;
}

.sortable.asc:before {
    border-bottom-color: #0d6efd;
}

.sortable.desc:after {
    border-top-color: #0d6efd;
}

/* Mobile responsiveness */
@media (max-width: 991.98px) {
    .navbar-nav {
        padding: 1rem 0;
    }
    
    .navbar-nav .nav-item {
        padding: 0.25rem 0;
    }

    .dropdown-menu {
        border: none;
        box-shadow: none;
        padding-left: 1rem;
    }

    .dropdown-item {
        padding: 0.5rem 1rem;
    }
}

/* Make sure dropdown menu is scrollable on mobile */
@media (max-width: 991.98px) {
    .navbar-collapse {
        max-height: calc(100vh - 70px);
        overflow-y: auto;
    }
}

/* Section Styles */
section {
    margin-bottom: 3rem;
    padding: 1.5rem;
    background-color: #fff;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    border: 1px solid rgba(0,0,0,0.04);
}

section h2 {
    color: #0068B3;
    padding-bottom: 1rem;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid #e9ecef;
    font-size: 1.75rem;
    font-weight: 600;
}

/* Tile Grid Styles */
.tiles-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
    padding: 1rem;
}

.object {
    background: white;
    border: 1px solid #e9ecef;
    border-radius: 12px;
    padding: 1.75rem;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.object:hover {
    transform: translateY(-6px);
    box-shadow: 0 8px 24px rgba(0, 104, 179, 0.12);
    border-color: rgba(0, 104, 179, 0.2);
}

.icon {
    margin-bottom: 1rem;
    width: 50px;
    height: 50px;
    object-fit: contain;
}

.info {
    text-align: center;
    width: 100%;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.title {
    font-weight: bold;
    margin-bottom: 0.75rem;
    color: #333;
    font-size: 1.1rem;
}

.description {
    font-size: 0.9rem;
    color: #666;
    margin-bottom: 1rem;
    line-height: 1.4;
    flex: 1;
}

.link, .linkfolder {
    display: inline-block;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    text-decoration: none;
    font-weight: 500;
    transition: opacity 0.2s, transform 0.2s, box-shadow 0.2s;
    color: white !important;
    width: 100%;
    max-width: 200px;
    margin-top: auto;
    border: 1px solid transparent;
}

.link {
    background-color: #0068B3;
    border-color: #0068B3;
}

.linkfolder {
    background-color: #198754;
    border-color: #198754;
}

.link:hover, .linkfolder:hover {
    opacity: 0.95;
    transform: translateY(-1px);
}

.link:focus, .linkfolder:focus {
    box-shadow: 0 0 0 0.2rem rgba(0, 104, 179, 0.35);
}

/* Container */
.container {
    max-width: 1400px;
    padding: 0 1rem;
}

/* Footer */
footer {
    margin-top: auto;
    padding: 1rem 0;
    background-color: #f8f9fa;
    border-top: 1px solid #dee2e6;
}

footer p {
    margin: 0;
    color: #6c757d;
}

/* Phone Numbers Dropdown */
.dropdown-menu .dropdown-item {
    padding: 0.75rem 1rem;
    transition: background-color 0.2s;
}

.dropdown-menu .dropdown-item:hover {
    background-color: #f8f9fa;
}

.dropdown-menu .dropdown-item .fw-bold {
    color: #0d6efd;
    margin-bottom: 0.25rem;
}

.dropdown-menu .dropdown-item small {
    font-size: 0.875rem;
}

.dropdown-menu .dropdown-item:hover small {
    color: #495057 !important;
}

.dropdown-menu .dropdown-divider {
    margin: 0.25rem 0;
}

/* ============================================================
   Home page search
   ============================================================ */
.tile-search-bar .input-group {
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    border-radius: 10px;
    overflow: hidden;
}

.tile-search-bar .form-control,
.tile-search-bar .input-group-text {
    border-color: #e9ecef;
    padding-top: 0.7rem;
    padding-bottom: 0.7rem;
}

.tile-search-bar .form-control:focus {
    border-color: #0068B3;
    box-shadow: none;
}

/* Keep the focus ring on the group rather than the single control, so the
   magnifier and the input read as one component. */
.tile-search-bar .input-group:focus-within {
    box-shadow: 0 0 0 0.2rem rgba(0, 104, 179, 0.2);
}

/* Category jump chips */
.category-jump {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.category-chip {
    display: inline-block;
    padding: 0.35rem 0.85rem;
    border-radius: 999px;
    background: #fff;
    border: 1px solid #e9ecef;
    color: #495057;
    font-size: 0.875rem;
    text-decoration: none;
    transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}

.category-chip:hover,
.category-chip:focus {
    background: #0068B3;
    border-color: #0068B3;
    color: #fff;
}

/* Jumping to a category should not tuck the heading under the fixed navbar. */
main section[id^="cat-"] {
    scroll-margin-top: 90px;
}

@media (max-width: 575.98px) {
    .category-jump { gap: 0.375rem; }
    .category-chip { font-size: 0.8125rem; padding: 0.3rem 0.7rem; }
}

/* ============================================================
   Admin dashboard
   ============================================================ */
.stat-card {
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(0, 104, 179, 0.12);
}
.stat-value {
    font-size: 1.9rem;
    font-weight: 600;
    line-height: 1.1;
    color: #0068B3;
}

/* Sparkline: plain divs rather than a charting library, so the dashboard
   stays self-contained and adds no external requests. */
.spark {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    height: 160px;
}
.spark-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    height: 100%;
}
.spark-bar {
    background: linear-gradient(180deg, #0068B3 0%, #4a9fd8 100%);
    border-radius: 3px 3px 0 0;
    min-height: 2px;
}
.spark-label {
    text-align: center;
    font-size: 0.7rem;
    color: #adb5bd;
    padding-top: 0.25rem;
}

/* Category breakdown bars (link analytics) */
.cat-row {
    display: grid;
    grid-template-columns: minmax(120px, 200px) 1fr auto auto;
    align-items: center;
    gap: 0.75rem;
    padding: 0.4rem 0;
}
.cat-name {
    font-size: 0.9rem;
    color: #495057;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.cat-track {
    background: #eef1f4;
    border-radius: 999px;
    height: 10px;
    overflow: hidden;
}
.cat-fill {
    height: 100%;
    background: linear-gradient(90deg, #0068B3 0%, #4a9fd8 100%);
    border-radius: 999px;
}
.cat-num {
    font-size: 0.85rem;
    text-align: right;
    min-width: 70px;
}

@media (max-width: 575.98px) {
    .cat-row { grid-template-columns: 1fr auto; }
    .cat-track { grid-column: 1 / -1; order: 3; }
}

/* ============================================================
   Tile management: drag to reorder
   ============================================================ */
.tile-row {
    transition: background-color 0.2s, opacity 0.2s;
}
.drag-cell {
    white-space: nowrap;
}
.drag-handle {
    cursor: grab;
    color: #adb5bd;
    font-size: 1.2rem;
    padding-right: 0.25rem;
    vertical-align: middle;
}
.drag-handle:active { cursor: grabbing; }
.tile-row:hover .drag-handle { color: #0068B3; }

.tile-row.dragging {
    opacity: 0.45;
    background-color: #eef6fc !important;
}
.tile-row.saving   { background-color: #fff8e1 !important; }
.tile-row.saved    { background-color: #e8f5e9 !important; }
.tile-row.save-failed { background-color: #fdecea !important; }

/* Up/down remain for keyboard use, but recede once dragging is available. */
.order-buttons { transform: scale(0.85); opacity: 0.55; }
.tile-row:hover .order-buttons,
.order-buttons:focus-within { opacity: 1; }

@media (hover: none) {
    /* No hover on touch devices, so keep the buttons plainly visible. */
    .order-buttons { opacity: 1; }
}

/* ============================================================
   Icon picker (tile add/edit)
   ============================================================ */
.icon-picker {
    border: 1px solid #dee2e6;
    border-radius: 8px;
    overflow: hidden;
    background: #fff;
}

/* Search and current selection stay put while the grid scrolls. */
.icon-picker-bar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid #e9ecef;
    background: #f8f9fa;
}
.icon-picker-bar .form-control { max-width: 260px; }

.icon-chosen {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
    flex: 1;
}
.icon-chosen img {
    width: 32px;
    height: 32px;
    object-fit: contain;
    flex: 0 0 32px;
    background: #eceff1;
    border-radius: 6px;
    padding: 3px;
}
.icon-chosen span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.icon-select {
    display: grid;
    /* Fixed-width cells: the library mixes 24px SVGs with 512px PNGs, and
       letting the grid size itself to the images made every row a different
       height. */
    grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
    gap: 6px;
    max-height: 340px;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 10px;
}
.icon-select:focus-visible {
    outline: 2px solid #0068B3;
    outline-offset: -2px;
}

.icon-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.35rem;
    padding: 0.5rem 0.25rem;
    border: 1px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.12s, border-color 0.12s;
}

/* Every icon gets the same box and is scaled to fit inside it, whatever its
   own dimensions or aspect ratio. */
.icon-thumb {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    /* Several icons in the library are white or near-white on a transparent
       background - the business centre logos in particular - and were
       invisible against a white cell. A light backdrop makes those readable
       without washing out the dark ones. */
    background: #eceff1;
    border-radius: 6px;
    padding: 3px;
}
.icon-thumb img {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
}

.icon-name {
    font-size: 0.7rem;
    line-height: 1.2;
    color: #6c757d;
    text-align: center;
    /* One line with an ellipsis. Wrapping long filenames was what made the
       rows ragged. The full name is in the cell's title attribute. */
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.icon-option:hover {
    background-color: #f1f5f9;
    border-color: #dee2e6;
}
.icon-option.selected {
    background-color: rgba(0, 104, 179, 0.08);
    border-color: #0068B3;
}
.icon-option.selected .icon-name {
    color: #0068B3;
    font-weight: 500;
}

@media (max-width: 575.98px) {
    .icon-picker-bar { flex-wrap: wrap; }
    .icon-picker-bar .form-control { max-width: none; flex: 1 1 100%; }
    .icon-select { grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); }
}

/* ============================================================
   Person cells: an ID means little on its own, so the address
   that identifies the human sits beneath it.
   ============================================================ */
.person-id {
    font-weight: 500;
    color: #212529;
}
.person-email {
    font-size: 0.78rem;
    line-height: 1.25;
    color: #6c757d;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 26ch;
}
.person-typed {
    font-size: 0.72rem;
    color: #adb5bd;
    font-style: italic;
}
.min-w-0 { min-width: 0; }

/* One consistent action column across every admin table. */
.table td .btn-group-sm > .btn {
    --bs-btn-padding-x: 0.5rem;
}

/* ============================================================
   Admin shell
   ============================================================ */
/* The body padding above exists to clear the public site's fixed-top
   navbar. The admin header is in normal flow and nothing is fixed, so on
   these pages that offset was just a 60px gap above the header. */
.admin-shell {
    padding-top: 0;
}

/* ============================================================
   Connections by state (admin dashboard)
   ============================================================ */
.usmap {
    display: grid;
    grid-template-columns: repeat(11, minmax(0, 1fr));
    gap: 5px;
    max-width: 760px;
    margin: 0 auto;
}

.usmap-gap {
    /* Keeps the grid's shape without drawing anything. */
    aspect-ratio: 1;
}

.usmap-state {
    aspect-ratio: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    border-radius: 6px;
    border: 1px solid rgba(0, 104, 179, 0.18);
    /* --fill runs 0..1; mixing against white keeps light values readable
       and dark values on-brand without a stepped palette. The rgba fallback
       comes first for browsers without color-mix, which get the same ramp
       via alpha instead. */
    background: rgba(0, 104, 179, var(--fill, 0));
    background: color-mix(in srgb, #0068B3 calc(var(--fill, 0) * 100%), #ffffff);
    color: #10334d;
    cursor: default;
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}

/* Once the tile is more than about half saturated, white text reads better. */
.usmap-state[style*="--fill: 0.6"],
.usmap-state[style*="--fill: 0.7"],
.usmap-state[style*="--fill: 0.8"],
.usmap-state[style*="--fill: 0.9"],
.usmap-state[style*="--fill: 1"] {
    color: #fff;
}

.usmap-state:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 104, 179, 0.25);
}

.usmap-state.is-empty {
    background: #f1f3f5;
    border-color: #e9ecef;
    color: #adb5bd;
}

.usmap-abbr {
    font-size: 0.68rem;
    font-weight: 600;
    line-height: 1;
}

.usmap-count {
    font-size: 0.58rem;
    line-height: 1;
    opacity: 0.85;
}

.usmap-legend {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    margin-top: 1rem;
    flex-wrap: wrap;
}

.usmap-swatch {
    width: 22px;
    height: 12px;
    border-radius: 3px;
    border: 1px solid rgba(0, 104, 179, 0.18);
    background: rgba(0, 104, 179, var(--fill, 0));
    background: color-mix(in srgb, #0068B3 calc(var(--fill, 0) * 100%), #ffffff);
}

@media (max-width: 767.98px) {
    .usmap { gap: 3px; }
    .usmap-abbr { font-size: 0.55rem; }
    .usmap-count { display: none; }
}
