/* Global Design Variables */
:root {
    --font-primary: 'Plus Jakarta Sans', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'Space Grotesk', system-ui, sans-serif;

    --bg-app: #ffffff;
    --bg-page: #f7f7f7;
    --bg-panel: #ffffff;
    --bg-muted: #f5f5f5;
    --bg-soft-red: #fff5f5;

    --border: #d8d8d8;
    --border-hover: #b8b8b8;

    --text-main: #1f1f1f;
    --text-muted: #5f6368;
    --text-subtle: #7a7a7a;
    --text-success: #16823a;
    --text-warning: #a05a00;
    --text-error: #b42318;

    --primary: #d1281b;
    --primary-dark: #a11f16;
    --primary-soft: #fff1f0;
    --link: #005ea8;

    --bubble-user: #d1281b;
    --bubble-bot: #ffffff;
    --bg-log-entry: #f7f7f7;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 10px 24px rgba(0, 0, 0, 0.12);
}

.hidden {
    display: none !important;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background: var(--bg-page);
    color: var(--text-main);
    font-family: var(--font-primary);
    min-height: 100vh;
    overflow-y: auto;
}

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #bdbdbd;
    border-radius: 10px;
}

.app-container {
    width: 100%;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.app-header {
    min-height: 72px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    padding: 0 32px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 10;
    box-shadow: var(--shadow-sm);
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.app-mark {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #ffffff;
    color: var(--primary);
    flex-shrink: 0;
    overflow: hidden;
}

.merlion-mark {
    width: 100%;
    height: 100%;
    object-fit: contain;
    transform: scale(1.05);
}

.logo-text h1 {
    font-family: var(--font-primary);
    font-size: 22px;
    font-weight: 700;
    letter-spacing: 0;
    color: var(--text-main);
}

.logo-text span {
    display: block;
    margin-top: 2px;
    font-size: 12px;
    color: var(--text-muted);
    letter-spacing: 0;
    text-transform: none;
}

.system-status {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-muted);
    padding: 7px 12px;
    border-radius: 6px;
    border: 1px solid var(--border);
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
}

.status-indicator.online {
    width: 8px;
    height: 8px;
    background-color: var(--text-success);
    border-radius: 50%;
    display: inline-block;
}

.app-directory {
    flex: 1;
    padding: 36px 32px 96px;
    background: var(--bg-page);
    max-width: 1280px;
    width: 100%;
    margin: 0 auto;
}

.directory-header {
    margin-bottom: 28px;
    max-width: 760px;
}

.directory-header h2 {
    font-size: 30px;
    line-height: 1.2;
    font-weight: 700;
    letter-spacing: 0;
    margin-bottom: 8px;
    color: var(--text-main);
}

.directory-header p {
    font-size: 16px;
    line-height: 1.55;
    color: var(--text-muted);
}

.directory-toolbar {
    margin-top: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
}

.reorder-hint {
    font-size: 13px;
    color: var(--text-subtle);
    display: flex;
    align-items: center;
    gap: 6px;
}

.reset-layout-btn {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 7px 12px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: border-color 0.2s, color 0.2s, background-color 0.2s;
}

.reset-layout-btn:hover {
    border-color: var(--border-hover);
    color: var(--text-main);
    background: var(--bg-muted);
}

.grid-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
    gap: 16px;
}

.service-card {
    position: relative;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    transition: border-color 0.2s, box-shadow 0.2s, transform 0.2s;
    box-shadow: var(--shadow-sm);
    cursor: grab;
}

.service-card:hover {
    border-color: var(--border-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.drag-handle {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-subtle);
    font-size: 13px;
    opacity: 0.5;
    cursor: grab;
    transition: opacity 0.2s, color 0.2s, background-color 0.2s;
    border-radius: 4px;
}

.drag-handle:hover {
    opacity: 1;
    color: var(--text-main);
    background: var(--bg-muted);
}

.service-card.dragging {
    opacity: 0.45;
    cursor: grabbing;
}

.service-card.drag-over {
    border-color: var(--primary);
    background: var(--primary-soft);
    box-shadow: 0 0 0 3px var(--primary), var(--shadow-md);
}

.agency-logo-wrap {
    width: 100%;
    height: 52px;
    margin-bottom: 18px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
}

.agency-logo {
    max-width: 156px;
    max-height: 48px;
    object-fit: contain;
    display: block;
    -webkit-user-drag: none;
    user-select: none;
}

.agency-logo-compact {
    max-width: 58px;
    max-height: 52px;
}

.agency-logo-text {
    width: fit-content;
    min-width: 76px;
    max-width: 100%;
    height: 42px;
    padding: 0 14px;
    border: 1px solid var(--border);
    border-left: 4px solid var(--primary);
    border-radius: 4px;
    color: var(--text-main);
    background: var(--bg-panel);
    font-weight: 800;
    font-size: 20px;
    letter-spacing: 0;
}

.agency-logo-text-small {
    font-size: 15px;
}

/* CPF's official logo asset is solid white with a transparent background —
   invert it to a dark mark so it reads on the card's white background. */
.agency-logo-invert {
    filter: invert(1);
}

.service-card h3 {
    font-size: 21px;
    font-weight: 700;
    letter-spacing: 0;
    margin-bottom: 4px;
    color: var(--text-main);
}

.service-card p {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    font-weight: 700;
    margin-bottom: 12px;
}

.card-desc {
    font-size: 14px;
    color: var(--text-muted);
    line-height: 1.5;
    margin-bottom: 24px;
    flex: 1;
}

.card-link {
    font-size: 14px;
    color: var(--link);
    text-decoration: none;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    align-self: flex-start;
}

.card-link:hover {
    color: var(--primary-dark);
    text-decoration: underline;
    text-underline-offset: 3px;
}

.card-link i {
    font-size: 12px;
}

.chat-trigger {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 1000;
    background: var(--primary);
    border: 1px solid var(--primary-dark);
    padding: 13px 20px;
    border-radius: 8px;
    font-weight: 700;
    font-size: 14px;
    color: #ffffff;
    cursor: pointer;
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    gap: 10px;
    transition: background-color 0.2s, transform 0.2s;
}

.chat-trigger:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
}

.pulse-indicator {
    width: 8px;
    height: 8px;
    background-color: #ffffff;
    border-radius: 50%;
    display: inline-block;
    animation: markerPulse 2s infinite;
}

@keyframes markerPulse {
    0% { transform: scale(0.95); opacity: 0.7; }
    70% { transform: scale(1.15); opacity: 1; }
    100% { transform: scale(0.95); opacity: 0.7; }
}

.chat-widget {
    position: fixed;
    bottom: 85px;
    right: 24px;
    z-index: 1001;
    width: 440px;
    height: 600px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.22);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: all 0.25s ease;
    transform-origin: bottom right;
}

.chat-widget.hidden {
    opacity: 0;
    transform: translateY(20px) scale(0.96);
    pointer-events: none;
}

.widget-header {
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    padding: 16px 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.widget-title h3 {
    font-size: 16px;
    font-weight: 700;
}

.widget-mark {
    width: 26px;
    height: 26px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--primary);
    color: #ffffff;
    flex-shrink: 0;
}

.widget-title span {
    font-size: 12px;
    color: var(--text-muted);
}

.minimize-btn {
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 16px;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s, color 0.2s;
}

.minimize-btn:hover {
    background: var(--bg-muted);
    color: var(--text-main);
}

.widget-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    background: var(--bg-muted);
}

.tab-btn {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-muted);
    padding: 12px 16px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: background-color 0.2s, color 0.2s;
}

.tab-btn:hover {
    color: var(--text-main);
}

.tab-btn.active {
    color: var(--primary);
    border-bottom: 3px solid var(--primary);
    background: #ffffff;
}

.widget-viewport {
    flex: 1;
    position: relative;
    display: flex;
    flex-direction: column;
    height: calc(100% - 110px);
}

.widget-pane {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.widget-pane.hidden {
    display: none !important;
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: #fafafa;
}

.message {
    display: flex;
    gap: 12px;
    max-width: 88%;
    animation: messageEntry 0.25s ease both;
}

.user-message {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    background: var(--bg-muted);
    border: 1px solid var(--border);
    color: var(--text-muted);
    flex-shrink: 0;
}

.user-message .message-avatar {
    background: var(--primary);
    border-color: var(--primary);
    color: #ffffff;
}

.message-content {
    padding: 12px 14px;
    border-radius: 8px;
    line-height: 1.45;
    font-size: 13.5px;
}

.user-message .message-content {
    background: var(--bubble-user);
    color: #ffffff;
}

.bot-message .message-content {
    background: var(--bubble-bot);
    color: var(--text-main);
    border: 1px solid var(--border);
}

.message-content p {
    margin-bottom: 8px;
}

.message-content p:last-child {
    margin-bottom: 0;
}

.message-content ul,
.message-content ol {
    margin-left: 18px;
    margin-top: 4px;
    margin-bottom: 4px;
}

.message-content li {
    margin-bottom: 3px;
}

.message-content a {
    color: var(--link);
    text-decoration: underline;
    text-underline-offset: 2px;
    font-weight: 600;
}

.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 6px 8px;
    align-items: center;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background-color: var(--text-muted);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

.suggestions-container {
    padding: 0 18px 10px;
    display: flex;
    gap: 8px;
    overflow-x: auto;
    flex-shrink: 0;
    background: #fafafa;
}

.suggestion-chip {
    background: #ffffff;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 7px 12px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: border-color 0.2s, color 0.2s, background-color 0.2s;
}

.suggestion-chip:hover {
    background: var(--primary-soft);
    border-color: var(--primary);
    color: var(--primary-dark);
}

.input-form {
    padding: 12px 18px 18px;
    background: #ffffff;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.input-wrapper:focus-within {
    border-color: var(--link);
    box-shadow: 0 0 0 3px rgba(0, 94, 168, 0.16);
}

.input-wrapper input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-main);
    padding: 12px 14px;
    font-size: 13.5px;
    font-family: var(--font-primary);
}

.input-wrapper input::placeholder {
    color: var(--text-subtle);
}

.send-btn {
    background: var(--primary);
    border: none;
    outline: none;
    color: #ffffff;
    width: 36px;
    height: 36px;
    border-radius: 4px;
    margin-right: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.2s;
}

.send-btn:hover {
    background: var(--primary-dark);
}

#logs-pane {
    background: #ffffff;
}

.logs-container {
    flex: 1;
    overflow-y: auto;
    padding: 18px;
    font-family: var(--font-mono);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.log-entry {
    background: var(--bg-log-entry);
    border-left: 3px solid var(--border);
    padding: 8px 12px;
    border-radius: 0 4px 4px 0;
    font-size: 12px;
    line-height: 1.5;
    color: var(--text-main);
}

.log-time {
    color: var(--text-muted);
    margin-right: 6px;
}

.log-tag {
    font-weight: 800;
    text-transform: uppercase;
    font-size: 10px;
    padding: 2px 5px;
    border-radius: 3px;
    margin-right: 6px;
}

.tag-system { background: #eceff3; color: var(--text-muted); }
.tag-search { background: #fff4dc; color: var(--text-warning); }
.tag-scrape { background: #eaf7ee; color: var(--text-success); }
.tag-error { background: #fff1f0; color: var(--text-error); }

.log-detail {
    display: block;
    margin-top: 4px;
    padding: 4px 8px;
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-muted);
    font-size: 11px;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 160px;
    overflow-y: auto;
}

@keyframes messageEntry {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes typingBounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-3px); }
}

@media(max-width: 500px) {
    .app-header {
        min-height: 72px;
        gap: 12px;
        padding: 12px 16px;
    }

    .app-mark {
        width: 36px;
        height: 36px;
    }

    .logo-text h1 {
        font-size: 19px;
    }

    .logo-text span {
        display: none;
    }

    .system-status {
        padding: 6px 8px;
        white-space: nowrap;
    }

    .app-directory {
        padding: 28px 16px 92px;
    }

    .directory-header h2 {
        font-size: 25px;
    }

    .reorder-hint {
        display: none;
    }

    .directory-toolbar {
        justify-content: flex-end;
    }

    .chat-trigger {
        right: 16px;
        bottom: 18px;
        max-width: calc(100% - 32px);
    }

    .chat-widget {
        width: calc(100% - 32px);
        height: calc(100% - 100px);
        bottom: 80px;
        right: 16px;
        left: 16px;
    }
}

/* ── SG Hub & Main Tabs Light Theme Aesthetics ────────────────────────────── */
.main-tabs {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 10px;
}

.main-tab-btn {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: 8px;
    padding: 10px 22px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: var(--font-mono);
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.main-tab-btn:hover {
    border-color: var(--border-hover);
    color: var(--text-main);
    background: var(--bg-muted);
}

.main-tab-btn.active-main-tab {
    background: var(--primary-soft) !important;
    color: var(--primary) !important;
    border-color: var(--primary) !important;
}

.hub-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 20px;
    margin-top: 10px;
}

.hub-card {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.2s, transform 0.2s;
}

.hub-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.hub-card h3 {
    margin: 0 0 14px 0;
    color: var(--primary);
    font-family: var(--font-mono);
    font-size: 18px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.sector-tab-btn {
    background: var(--bg-muted);
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 14px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
}

.sector-tab-btn:hover {
    border-color: var(--border-hover);
    color: var(--text-main);
}

.sector-tab-btn.active-sector {
    background: var(--primary-soft) !important;
    color: var(--primary) !important;
    border-color: var(--primary) !important;
}

/* ── SG Hub Sub-tab Button Aesthetics ────────────────────────────────────── */
.hub-sub-tab-btn {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: 6px;
    padding: 6px 14px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    font-family: var(--font-primary);
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.hub-sub-tab-btn:hover {
    border-color: var(--border-hover);
    color: var(--text-main);
    background: var(--bg-muted);
}

.hub-sub-tab-btn.active-hub-sub-tab {
    background: var(--primary-soft) !important;
    color: var(--primary) !important;
    border-color: var(--primary) !important;
}

.hub-sub-pane {
    margin-top: 10px;
}
