/* ===============================
   Global theme variables
   =============================== */
:root {
    --bg: #0f1116;
    --panel: #1a1d24;
    --panel-2: #2a2f3a;
    --text: #fff;
    --muted: #52555b;
    --brand: #2f80ed;
    --brand-2: #2565c4;
    --ok: #30d158;
    --warn: #ffd60a;
    --danger: #ff4d4f;
}

/* ===============================
   Base + Layout
   =============================== */
* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: 'Inter', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    display: flex;
    min-height: 100vh;
}

/* Page layout container (sidebar + content) */
#app-root {
    display: flex;
    min-height: 100vh;
    width: 100%;
}

/* ===============================
   others needed
   =============================== */
.page {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 10px;
}

.panel {
    background: var(--panel);
    border: 1px solid var(--panel-2);
    border-radius: 14px;
    padding: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px 16px;
}

.form-grid .full {
    grid-column: 1 / -1;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.helper {
    color: var(--muted);
    font-size: 12px;
}

.error-message {
    color: var(--danger);
    background: rgba(255, 0, 0, 0.05);
    border: 1px solid rgba(255, 0, 0, 0.2);
    padding: 8px 10px;
    border-radius: 10px;
    margin-bottom: 12px;
}

.logo {
    text-align: center;
    margin-bottom: 16px;
}

.logo img {
    max-width: 180px;
    height: auto;
}

.chipbar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    min-height: 22px;
}

/* Small pill for filter chips */
.chip {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 999px;
    background: var(--panel-2);
    color: #ddd;
    border: 1px solid #333a48;
    font-size: 12px;
}

/* ===============================
   Sidebar
   =============================== */
.sidebar {
    width: 250px;
    background: var(--panel);
    padding-top: 30px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.sidebar h2 {
    text-align: center;
    margin-bottom: 30px;
    font-size: 18px;
    color: var(--brand);
    letter-spacing: 1px;
}

/* ===============================
   Nav / Menu
   =============================== */
.menu {
    list-style: none;
    padding: 0;
    margin: 0;
}

.menu li {
    margin: 1px 0 1px 0;
}

.menu li>a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 15px 20px;
    color: #ccc;
    text-decoration: none;
    background: none;
    border: none;
    border-radius: 6px;
    font-size: 16px;
    transition: background 0.25s, color 0.25s;
    width: 100%;
    box-sizing: border-box;
}

.menu li>a:hover {
    background: var(--panel-2);
    color: #fff;
}

.menu li.active>a {
    background: var(--brand);
    color: #fff;
}

.menu li>a:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
}

.menu li i {
    font-size: 16px;
    margin-right: 10px;
}

/* Padding for the logout form inside the menu */
.menu-form {
    padding: 12px 20px;
}

/* ===============================
   Content area
   =============================== */
.content {
    flex: 1;
    padding: 40px;
    margin-left: 0;
    min-width: 0;
    overflow-y: auto;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

h1 {
    margin: 0 0 20px 0;
    font-size: 24px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 12px;
}

/* ===============================
   Buttons (existing)
   =============================== */
.edit-btn,
.pw-btn,
.logout-btn,
.add-btn,
.normal-btn {
    background-color: var(--brand);
    color: #fff;
    border: none;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s;
}
.edit-btn[disabled],
.pw-btn[disabled],
.logout-btn[disabled],
.add-btn[disabled],
.normal-btn[disabled] {
    opacity: .6;
    cursor: not-allowed;
}

.edit-btn,
.pw-btn {
    padding: 8px 16px;
    font-size: 14px;
}

.logout-btn {
    padding: 10px 18px;
    font-size: 15px;
    border-radius: 8px;
    text-decoration: none;
}

.add-btn,
.normal-btn {
    padding: 10px 20px;
    margin-bottom: 20px;
    font-size: 14px;
}

.edit-btn:hover,
.pw-btn:hover,
.logout-btn:hover,
.add-btn:hover,
.normal-btn:hover {
    background-color: var(--brand-2);
}

/* Emphasize the temporary password without inline styles */
.pw-code {
    font-weight: 600;
    font-size: 18px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
    display: inline-block;
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid #d6e2ff;
    background: #f0f4ff;
    color: #0b5fff;
    letter-spacing: .3px;
    user-select: all;
}

/* Generic button style used in integration cards */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 10px;
    font-weight: 700;
    font-size: 14px;
}

.btn-connect {
    background: var(--ok);
    color: #fff;
    cursor: pointer;
}

.btn-connect:hover {
    background: #28a745;
}

.btn-connected {
    background: #1c7d32;
    color: #fff;
}

.btn-disabled {
    background: #555;
    color: #cfcfcf;
    cursor: not-allowed;
}

/* ===============================
   Boxes / Panels
   =============================== */
.info-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
    margin-bottom: 20px;
}

.info-box {
    background-color: var(--panel);
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
}

.info-box h3 {
    margin: 0 0 10px;
    font-size: 16px;
    color: var(--brand);
}

.info-box p {
    margin: 0;
    font-size: 14px;
    color: #ddd;
}

.package-section {
    background-color: var(--panel);
    padding: 20px;
    margin-bottom: 20px;
    border-radius: 10px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
}

.package-section h3 {
    margin: 0 0 10px;
    font-size: 16px;
    color: var(--brand);
}

.package-section p {
    font-size: 14px;
    color: #ddd;
}

/* Cards (admin) */
.card {
    margin-bottom: 1rem;
    padding: 0.75rem 1rem;
    background: var(--panel);
    border-radius: 10px;
}

/* ===============================
   Integrationer grid
   =============================== */
.grid-wrap {
    max-width: 1200px;
    margin: 0 auto;
}

.integration-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(260px, 1fr));
    gap: 32px;
    justify-items: center;
    align-items: stretch;
}

.integration-card {
    width: 100%;
    background: var(--panel);
    border-radius: 14px;
    padding: 32px;
    box-shadow: 0 0 10px rgba(0, 0, 0, .3);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    min-height: 200px;
}

.integration-card img {
    height: 56px;
    width: auto;
    object-fit: contain;
}

/* ===============================
   Tables
   =============================== */
.watchlist {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
}

.watchlist tr {
    background-color: var(--panel);
    border-bottom: 1px solid var(--panel-2);
}

.watchlist td {
    padding: 15px;
    font-size: 14px;
}

.watchlist .actions {
    text-align: right;
}

.watchlist button {
    background: none;
    border: none;
    cursor: pointer;
    margin-left: 10px;
    font-size: 16px;
    color: #ccc;
    transition: color 0.3s;
}

.watchlist button:hover {
    color: #fff;
}

td {
    text-align: center;
}

td.actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
}

/* ===============================
   Status pills
   =============================== */
.status-active {
    color: var(--brand);
    font-weight: 600;
}

.status-inactive {
    color: #888;
    font-weight: 600;
}

/* ===============================
   Login page
   =============================== */
   /* Center ONLY the login page, not the whole app */
.login-body {
    justify-content: center;
    align-items: center;
    height: 100vh;
}
.logo img {
    max-width: 180px;
    height: auto;
}
.login-container {
    background-color: var(--panel);
    padding: 40px;
    border-radius: 12px;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
    max-width: 400px;
    width: 100%;
    text-align: center;
    margin: 0 16px;
}
.login-container .logo img {
    max-width: 220px;
    margin-bottom: 30px;
}

.login-container h2 {
    margin-bottom: 20px;
    font-weight: 600;
    color: #fff;
}

.login-container .form-group {
    margin-bottom: 20px;
    text-align: left;
}

.login-container .form-group label {
    display: block;
    margin-bottom: 8px;
    font-size: 14px;
    color: #aaa;
}
.login-container input[type="text"],
.login-container input[type="password"] {
    background: var(--panel-2);
    color: #fff;
    border: none;
    width: 100%;
    border-radius: 8px;
    padding: 12px;
    font-size: 14px;
}
.login-container input[type="text"]:focus,
.login-container input[type="password"]:focus {
    outline: 2px solid var(--brand);
}

.login-btn {
    background: var(--brand);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s;
    width: 100%;
    padding: 14px;
}

.login-btn:hover {
    background: var(--brand-2);
}

.login-container .info-text {
    margin-top: 15px;
    font-size: 13px;
    color: #aaa;
}

.login-container .info-text a {
    color: var(--brand);
    text-decoration: none;
}

.login-container .info-text a:hover {
    text-decoration: underline;
}

.login-container .footer-text {
    margin-top: 20px;
    font-size: 13px;
    color: #888;
}

.login-container .footer-text a {
    color: var(--brand);
    text-decoration: none;
}

.login-container .footer-text a:hover {
    text-decoration: underline;
}

/* ===============================
   Alerts (shared)
   =============================== */
.alert {
    padding: 10px;
    border-radius: 8px;
    margin-bottom: 12px;
    font-size: 14px;
}

.alert--error {
    background: #3a1323;
    color: #ffb3c1;
    border: 1px solid #6b1d36;
}

.alert--success {
    background: #11301d;
    color: #b2f5ca;
    border: 1px solid #1d6b3e;
}

/* ===============================
   Dialog (native <dialog>) shared
   =============================== */
dialog {
    border: none;
    border-radius: 12px;
    max-width: 480px;
    width: 100%;
    padding: 0;
}

dialog::backdrop {
    background: rgba(0, 0, 0, .6);
}

.dialog__header {
    padding: 20px;
    background: #141824;
    color: #fff;
    border-radius: 12px 12px 0 0;
}

.dialog__body {
    padding: 20px;
    background: #0f1116;
    color: #fff;
    border-radius: 0 0 12px 12px;
}

/* ===============================
   Field error bubble (used on watch_form)
   =============================== */
.field-error {
    position: relative;
    display: inline-block;
    background: #222;
    color: #ffd60a;
    font-size: 13px;
    border-radius: 6px;
    padding: 6px 12px 6px 12px;
    margin-top: 4px;
    margin-bottom: 2px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
    z-index: 2;
}

.field-error::after {
    content: '';
    position: absolute;
    top: -8px;
    left: 18px;
    border-width: 0 8px 8px 8px;
    border-style: solid;
    border-color: transparent transparent #222 transparent;
    display: block;
    width: 0;
}

/* ===============================
   Forms (shared helpers to replace inline)
   =============================== */
.checkbox-lg {
    width: 22px;
    height: 22px;
    accent-color: #2f80ed;
}

.select-multi {
    width: 100%;
    min-height: 38px;
}

.select-single {
    width: 100%;
    min-height: 38px;
}

/* label + action row */
.field-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

/* subtle action link/button */
.clear-link {
    background: none;
    border: 0;
    font: inherit;
    text-decoration: underline;
    cursor: pointer;
    padding: 0;
    color: #333;
}

.clear-link:hover {
    text-decoration: none;
}

.range-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.number-input-90 {
    width: 90px;
}

.pre-wrap {
    white-space: pre-wrap;
    overflow: auto;
}

/* Date input look */
input[type="date"] {
    height: 40px;
}

input[type="date"]::-webkit-calendar-picker-indicator {
    filter: none !important;
    opacity: 1 !important;
}

/* ===============================
   Sync overlay (modal-like progress)
   =============================== */
.sync-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .55);
    display: grid;
    place-items: center;
    z-index: 9999;
}

.sync-overlay[hidden] {
    display: none !important;
}

.sync-box {
    width: min(520px, 92vw);
    background: #121826;
    border: 1px solid #2a3447;
    border-radius: 12px;
    padding: 18px 16px;
    color: #e6e6e6;
    box-shadow: 0 10px 30px rgba(0, 0, 0, .35);
}

.sync-title {
    font-size: 18px;
    margin-bottom: 10px;
}

.sync-bar {
    height: 12px;
    background: #0b1220;
    border-radius: 999px;
    overflow: hidden;
    border: 1px solid #1f2a44;
}

.sync-bar-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #3b82f6, #22d3ee);
    transition: width .25s ease;
    will-change: width;
    transform: translateZ(0);
}

.sync-percent {
    margin-top: 8px;
    font-variant-numeric: tabular-nums;
}

.sync-msg {
    margin-top: 6px;
    color: #aab4c5;
    font-size: 14px;
}

/* Freeze UI under overlay */
body.sync-lock {
    overflow: hidden;
}

body.sync-lock #app-root {
    pointer-events: none;
    filter: saturate(0.5) brightness(0.9);
}

/* Overlay remains interactive */
.sync-overlay,
.sync-overlay * {
    pointer-events: auto;
}

/* ===============================
   Utilities (replace inline styles)
   =============================== */
.hidden {
    display: none !important;
}

.block {
    display: block !important;
}

.inline {
    display: inline !important;
}

.flex {
    display: flex !important;
}

.flex-wrap {
    flex-wrap: wrap !important;
}

.items-center {
    align-items: center !important;
}

.justify-between {
    justify-content: space-between !important;
}

.justify-end {
    justify-content: flex-end !important;
}

.gap-8 {
    gap: 8px !important;
}

.gap-10 {
    gap: 10px !important;
}

.gap-12 {
    gap: 12px !important;
}

.gap-24 {
    gap: 24px !important;
}

.w-full {
    width: 100% !important;
}

.flex-1 {
    flex: 1 1 auto !important;
}

.h-40 {
    height: 40px !important;
}

.min-h-38 {
    min-height: 38px !important;
}

.min-w-280 {
    min-width: 280px !important;
}

.w-80 {
    width: 80px !important;
}

.w-90 {
    width: 90px !important;
}

.mt-8 {
    margin-top: 8px !important;
}

.mt-10 {
    margin-top: 10px !important;
}

.mt-16 {
    margin-top: 16px !important;
}

.mb-4 {
    margin-bottom: 4px !important;
}

.mb-14 {
    margin-bottom: 14px !important;
}

.mb-16 {
    margin-bottom: 16px !important;
}

.ml-10 {
    margin-left: 10px !important;
}

.m-0 {
    margin: 0 !important;
}

.text-12 {
    font-size: 12px !important;
}

.text-13 {
    font-size: 13px !important;
}

.text-14 {
    font-size: 14px !important;
}

.text-muted {
    color: var(--muted) !important;
}

.text-warn {
    color: var(--warn) !important;
}

.cursor-pointer {
    cursor: pointer !important;
}

.link-accent {
    color: lightskyblue !important;
}

/* watchlist amount too much warn */
.alert-warn {
    background: #3d3d3d;
    border: 1px solid #ffffff;
    padding: 10px;
    border-radius: 6px;
}

/* New generic buttons (optional helpers for admin) */
.btn-primary {
    background: var(--brand);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 10px 14px;
    font-weight: 600;
}

.btn-primary:hover {
    background: var(--brand-2);
}

.btn-secondary {
    background: var(--panel);
    color: #fff;
    border: 1px solid #2a2f3a;
    border-radius: 8px;
    padding: 10px 14px;
}

.btn-secondary:hover {
    background: #2a2f3a;
}

.btn-danger {
    background: var(--danger);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 8px 12px;
}

.btn-danger:hover {
    filter: brightness(1.05);
}

.btn-ghost {
    background: transparent;
    border: 0;
    color: inherit;
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
}

.btn-ghost:hover {
    background: var(--panel-2);
}

/* Toggle icon (for watchlist active/inactive) */
.icon-toggle {
    font-size: 20px;
    line-height: 1;
    vertical-align: middle;
}

.icon-toggle.is-active {
    color: var(--brand);
}

.icon-toggle:not(.is-active) {
    color: #888;
}

/* === Mapping table (for zoho-mapping pages) === */
.mapping-table {
    width: 100%;
    border-collapse: collapse;
}

.mapping-table th,
.mapping-table td {
    padding: 5px;
    text-align: left;
}

/* Zoho mapping form: vertical rhythm between alert/table/actions */
.mapping-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* --- Added for Zoho contact-link mode UX --- */
.divider-top {
    border-top: 1px solid var(--panel-2);
    padding-top: 8px;
}

.ml-6 {
    margin-left: 6px !important;
}

/* === Saving animation === */
/* Fullscreen overlay; hidden by default */
.saving-overlay {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.4);
    z-index: 9999;
}

/* When visible */
.saving-overlay.saving-overlay--visible {
    display: flex;
}

.saving-overlay-box {
    background: #ffffff;
    border-radius: 12px;
    padding: 16px 24px;
    min-width: 200px;
    display: flex;
    flex-direction: column;
    align-items: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}

/* SVG spinner */
.saving-overlay-spinner {
    width: 48px;
    height: 48px;
    margin-bottom: 8px;
    transform-origin: center;
    transform-box: fill-box;
    animation: saving-spin 1s linear infinite;
}

.saving-overlay-spinner-circle {
    fill: none;
    stroke: #0f62fe;
    /* tweak to match your brand color */
    stroke-width: 4;
    stroke-linecap: round;
    stroke-dasharray: 90;
    stroke-dashoffset: 60;
}

.saving-overlay-text {
    font-size: 14px;
    color: #333333;
    font-weight: 500;
}

@keyframes saving-spin {
    to {
        transform: rotate(360deg);
    }
}

/* === Small utilities === */
.text-center {
    text-align: center !important;
}

.mt-24 {
    margin-top: 24px !important;
}

/* ===== Utilities used by the defaults modal ===== */
.flex-row {
    display: flex;
    align-items: center;
}

.mb-8 {
    margin-bottom: 8px !important;
}

.mb-12 {
    margin-bottom: 12px !important;
}

.mt-12 {
    margin-top: 12px !important;
}

.maxh-40vh {
    max-height: 40vh;
    overflow: auto;
}

/* Small pill badge for field types */
.pill {
    display: inline-block;
    font-size: 12px;
    padding: 2px 6px;
    border-radius: 999px;
    background: #2a2f3a;
    color: #ddd;
    border: 1px solid #333a48;
}

/* Input look in modals to match UI */
.input {
    background: var(--panel-2);
    color: #fff;
    border: 1px solid #333a48;
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 14px;
    height: 40px;
}

.input:focus {
    outline: 2px solid var(--brand);
}

/* Simple vertical stack with 24px gap */
.vstack-24 {
    display: flex !important;
    flex-direction: column !important;
    gap: 24px !important;
}

/* ===============================
   Dashboard layout
   =============================== */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px;
    align-items: stretch;
}

/* inside each dashboard card, spread content vertically */
.dashboard-grid .package-section {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    /* no big empty block at bottom */
}

/* make charts take up more of the card height */
.dashboard-grid .package-section canvas {
    margin-top: 12px;
    flex: 1 0 auto;
    max-height: 320px;
}

/* bottom card spans both columns */
.dashboard-card-span-2 {
    grid-column: 1 / -1;
}

/* big white KPI number */
.kpi-number {
    font-size: 32px;
    font-weight: 700;
    margin: 4px 0 0;
    color: #fff;
}

/* interval selector under the chart */
.interval-form {
    margin-top: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.interval-form label {
    font-size: 14px;
    color: var(--muted);
}

.interval-form select {
    background: var(--panel-2);
    color: #fff;
    border: 1px solid var(--panel-2);
    border-radius: 6px;
    padding: 6px 8px;
    min-height: 32px;
}

/* stack grid on small screens */
@media (max-width: 900px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
    }

    .dashboard-card-span-2 {
        grid-column: auto;
    }
}

/* === Mapping grid/cards (added) === */
.map-grid {
    display: grid;
    gap: 16px;
}

/* Normal: 2 cards on top, 1 full-width below */
.map-grid--normal {
    grid-template-columns: repeat(2, minmax(280px, 1fr));
}

.map-box--span2 {
    grid-column: 1 / -1;
}

/* Premium: 2x2 grid */
.map-grid--premium {
    grid-template-columns: repeat(2, minmax(280px, 1fr));
}

/* Card look for each group */
.map-box {
    background: var(--panel);
    border: 1px solid var(--panel-2);
    border-radius: 12px;
    padding: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .18);
}

.map-box__header {
    margin-bottom: 8px;
}

.map-box__title {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

/* Two-column inner split for the bottom card on normal page */
.two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

/* Responsive */
@media (max-width: 980px) {

    .map-grid--normal,
    .map-grid--premium {
        grid-template-columns: 1fr;
    }

    .map-box--span2 {
        grid-column: auto;
    }

    .two-col {
        grid-template-columns: 1fr;
    }
}

/* ===============================
   Responsive
   =============================== */
@media (max-width: 900px) {

    .info-grid,
    .integration-grid {
        grid-template-columns: 1fr;
    }

    .sidebar {
        width: 100px;
        min-width: 100px;
    }

    .content {
        padding: 20px;
    }
}