/* ============================================
   PH Politics Database — Shared Design System
   ============================================ */

/* --- CSS Custom Properties --- */
:root {
    --color-bg: #f6f8fa;
    --color-surface: #fff;
    --color-border: #e1e4e8;
    --color-border-light: #eaecef;
    --color-text: #24292e;
    --color-text-muted: #586069;
    --color-text-light: #6a737d;
    --color-primary: #0366d6;
    --color-primary-hover: #0056b3;
    --color-accent: #ffd33d;
    --color-accent-border: #e3b341;
    --color-nav-bg: #24292e;
    --color-success: #28a745;
    --color-danger: #d73a49;
    --color-warning-bg: #fffdef;
    --color-warning-border: #f1e05a;
    --color-dynasty-bg: #f1f8ff;
    --color-dynasty-border: #c8e1ff;
    --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --shadow-card: 0 4px 20px rgba(0, 0, 0, 0.08);
    --shadow-light: 0 4px 10px rgba(0, 0, 0, 0.05);
    --shadow-hover: 0 12px 40px rgba(0, 0, 0, 0.15);
    --max-width: 1200px;
    --max-width-narrow: 1100px;
    --max-width-profile: 900px;
}

/* --- Reset & Base --- */
* { box-sizing: border-box; }

body {
    font-family: var(--font-family);
    margin: 0;
    background-color: var(--color-bg);
    color: var(--color-text);
}

a { color: var(--color-primary); text-decoration: none; font-weight: 600; }
a:hover { text-decoration: underline; }

/* --- Navigation Bar --- */
.site-nav {
    background: var(--color-nav-bg);
    padding: 15px 40px;
    display: flex;
    gap: 20px;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 1000;
    flex-wrap: wrap;
}

.site-nav a {
    color: white;
    text-decoration: none;
    font-weight: 600;
    font-size: 14px;
    opacity: 0.8;
    white-space: nowrap;
}

.site-nav a:hover,
.site-nav a.active { opacity: 1; text-decoration: none; }

.site-nav .logo {
    font-size: 18px;
    margin-right: 20px;
    color: var(--color-accent) !important;
    opacity: 1;
}

.nav-links {
    display: flex;
    gap: 20px;
    align-items: center;
    flex-wrap: wrap;
    flex: 1;
}

/* Hamburger */
.hamburger {
    display: none;
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 5px;
    margin-left: auto;
}

/* Global Search in Nav */
.nav-search-container {
    margin-left: auto;
    position: relative;
}

.nav-search-input {
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid #444;
    background: #333;
    color: white;
    font-size: 13px;
    width: 220px;
    outline: none;
    transition: width 0.2s;
}

.nav-search-input:focus {
    width: 300px;
    border-color: var(--color-accent);
}

.nav-search-input::placeholder { color: #999; }

.search-results-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 6px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-card);
    width: 380px;
    max-height: 400px;
    overflow-y: auto;
    z-index: 2000;
    display: none;
}

.search-results-dropdown.visible { display: block; }

.search-result-group-header {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--color-text-muted);
    padding: 8px 15px 4px;
    border-bottom: 1px solid var(--color-border);
    background: #fafbfc;
}

.search-results-dropdown .search-result-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 15px;
    font-size: 14px;
    color: var(--color-text);
    text-decoration: none;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
}

.search-result-item:hover {
    background: var(--color-bg);
    text-decoration: none;
}

.search-result-type {
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 10px;
    font-weight: 700;
    text-transform: uppercase;
}

.type-politician { background: #ffeef0; color: var(--color-danger); }
.type-dynasty { background: #e6ffed; color: var(--color-success); }
.type-party { background: #dbedff; color: var(--color-primary); }
.type-province { background: #fff8e1; color: #e36209; }

/* --- Footer --- */
.site-footer {
    text-align: center;
    padding: 30px 20px;
    color: var(--color-text-muted);
    font-size: 14px;
    border-top: 1px solid var(--color-border);
    margin-top: 40px;
}

/* --- Breadcrumbs --- */
.breadcrumb {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 12px 40px;
    font-size: 13px;
    color: var(--color-text-muted);
}

.breadcrumb a { font-weight: 500; }
.breadcrumb span { color: var(--color-text); font-weight: 600; }

/* --- Layout --- */
.main-content {
    padding: 40px;
    max-width: var(--max-width);
    margin: 0 auto;
}

.content {
    max-width: var(--max-width);
    margin: 0 auto;
    padding-top: 20px;
}

.container {
    background: var(--color-surface);
    padding: 25px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-light);
    margin-bottom: 30px;
}

.profile-card {
    background: var(--color-surface);
    padding: 30px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
    margin-bottom: 30px;
}

/* --- Page Titles --- */
h1 {
    color: var(--color-text);
    text-align: center;
    margin-bottom: 30px;
}

h1.profile-title {
    text-align: left;
    margin-top: 0;
    border-bottom: 2px solid var(--color-border-light);
    padding-bottom: 10px;
}

.subtitle {
    text-align: center;
    color: var(--color-text-muted);
    margin-bottom: 30px;
}

.meta {
    color: var(--color-text-muted);
    margin-bottom: 30px;
}

/* --- Stats --- */
.summary-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin: 25px 0;
}

.stat-box {
    background: var(--color-bg);
    padding: 15px;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    text-align: center;
}

.stat-label {
    font-size: 12px;
    color: var(--color-text-muted);
    text-transform: uppercase;
    font-weight: bold;
}

.stat-value {
    font-size: 28px;
    color: var(--color-primary);
    font-weight: bold;
    margin-top: 5px;
}

.stat-value-sm { font-size: 18px; }

.stats-grid {
    display: flex;
    justify-content: center;
    gap: 40px;
    margin-top: 30px;
}

.stat-item { flex: 1; text-align: center; }
.stat-num { font-size: 36px; font-weight: 800; color: var(--color-text); }

/* --- Homepage --- */
.hero {
    background: var(--color-nav-bg);
    color: white;
    padding: 80px 20px;
    text-align: center;
}

.hero h1 { font-size: 42px; margin: 0; color: var(--color-accent); text-align: center; }
.hero p { font-size: 18px; opacity: 0.8; margin-top: 10px; }

.nav-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 25px;
    max-width: var(--max-width);
    margin: -40px auto 60px;
    padding: 0 20px;
}

.nav-card {
    background: var(--color-surface);
    padding: 35px;
    border-radius: var(--radius-lg);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.1);
    text-decoration: none;
    color: inherit;
    transition: transform 0.2s, box-shadow 0.2s;
    border: 1px solid var(--color-border);
    text-align: center;
}

.nav-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-hover);
    border-color: var(--color-primary);
    text-decoration: none;
}

.nav-card h2 { margin: 0 0 15px 0; color: var(--color-primary); font-size: 24px; }
.nav-card p { margin: 0; color: var(--color-text-muted); font-size: 15px; line-height: 1.5; font-weight: 400; }

/* --- Charts --- */
.charts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 30px;
}

.chart-container {
    background: var(--color-bg);
    padding: 20px;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    height: 350px;
}

/* --- Badges --- */
.badge {
    display: inline-block;
    padding: 2px 8px;
    font-size: 12px;
    border-radius: 12px;
    background: var(--color-border);
    color: var(--color-text);
}

.leadership-badge { background: var(--color-accent); color: var(--color-text); font-weight: bold; }
.leader-badge { background: var(--color-accent); color: var(--color-text); font-weight: bold; margin-left: 5px; }
.admin-badge { background: var(--color-danger); color: white; }
.fat-badge { background: var(--color-danger); color: white; }
.thin-badge { background: var(--color-success); color: white; }
.party-badge { background: var(--color-border); color: var(--color-text); }
.dynasty-badge { background: var(--color-dynasty-bg); color: var(--color-primary); border: 1px solid var(--color-dynasty-border); }

.badge-sm { font-size: 11px; padding: 1px 6px; border-radius: var(--radius-sm); }

/* --- Status Badges --- */
.badge-active { background: #e6ffed; color: var(--color-success); border: 1px solid #acf2bd; }
.badge-historical { background: #f6f8fa; color: var(--color-text-muted); border: 1px solid var(--color-border); }


/* --- Turncoat Badge --- */
.turncoat-badge {
    background: #ffeef0;
    color: var(--color-danger);
    font-weight: bold;
    border: 1px solid #fdaeb7;
}

.turncoat-highlight {
    border-left: 4px solid var(--color-danger) !important;
    background: #fff5f5 !important;
}

/* --- DataTables Overrides --- */
table.dataTable {
    border-collapse: collapse !important;
    border-radius: var(--radius-md);
    overflow: hidden;
    font-size: 14px;
}

table.dataTable thead th {
    background-color: var(--color-primary);
    color: white;
    padding: 12px;
    border: none;
}

.datatable-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    
    /* Scroll Shadow Technique */
    background: 
        /* Shadow covers (to hide shadows when at edges) */
        linear-gradient(to right, var(--color-surface) 30%, rgba(255,255,255,0)),
        linear-gradient(to left, var(--color-surface) 30%, rgba(255,255,255,0)),
        /* Real shadows */
        radial-gradient(farthest-side at 0 50%, rgba(0,0,0,0.1), rgba(0,0,0,0)),
        radial-gradient(farthest-side at 100% 50%, rgba(0,0,0,0.1), rgba(0,0,0,0));
    background-repeat: no-repeat;
    background-color: var(--color-surface);
    background-size: 40px 100%, 40px 100%, 14px 100%, 14px 100%;
    
    /* 
      1. Left cover: left edge 
      2. Right cover: right edge
      3. Left shadow: left edge
      4. Right shadow: right edge 
    */
    background-position: 0 0, 100% 0, 0 0, 100% 0;
    
    /* 
      The covers must scroll with the content (local), 
      while the shadows stay fixed on the edges (scroll) 
    */
    background-attachment: local, local, scroll, scroll;
}

/* --- Filters --- */
.filters {
    margin-bottom: 25px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 15px;
    background: var(--color-bg);
    padding: 20px;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
}

.filter-group { display: flex; flex-direction: column; }

.filters label {
    font-size: 11px;
    color: var(--color-text-muted);
    margin-bottom: 4px;
    font-weight: 700;
    text-transform: uppercase;
}

.filters select,
.filters input {
    padding: 8px;
    border-radius: 6px;
    border: 1px solid #d1d5da;
    font-size: 13px;
    width: 100%;
    box-sizing: border-box;
}

/* --- Tabs --- */
.tabs {
    border-bottom: 2px solid var(--color-border);
    margin-bottom: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.tab-buttons { display: flex; }

.tab-button {
    background: none;
    border: none;
    padding: 15px 20px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 600;
    color: var(--color-text-muted);
    border-bottom: 3px solid transparent;
}

.tab-button.active { color: var(--color-text); border-bottom-color: var(--color-primary); }

.tab-content { display: none; }
.tab-content.active { display: block; }

.filter-switch {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 600;
}

/* --- History (Accordion) --- */
.history-item {
    background: var(--color-surface);
    padding: 15px;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    margin-bottom: 10px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
}

.history-header strong { font-size: 16px; color: var(--color-primary); }
.history-content { display: none; margin-top: 15px; padding-top: 15px; border-top: 1px solid var(--color-border); }

.grid-3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 15px;
    font-size: 14px;
}

/* --- History Table (Dynasty/Province) --- */
.history-table { width: 100%; border-collapse: collapse; margin-top: 20px; }
.history-table th { text-align: left; background: var(--color-primary); color: white; padding: 10px; font-size: 14px; }
.history-table td { padding: 10px; border-bottom: 1px solid #eee; vertical-align: top; font-size: 14px; }

/* --- Cabinet Table --- */
.cabinet-table { width: 100%; border-collapse: collapse; }
.cabinet-table th { text-align: left; padding: 12px 25px; background: #fafbfc; border-bottom: 1px solid var(--color-border); font-size: 13px; color: var(--color-text-muted); text-transform: uppercase; }
.cabinet-table td { padding: 12px 25px; border-bottom: 1px solid var(--color-bg); font-size: 14px; vertical-align: top; }
.cabinet-table tr:hover { background-color: #fcfcfc; }
.role-cell { font-weight: 600; color: var(--color-text); width: 35%; }
.name-cell a { color: var(--color-primary); text-decoration: none; font-weight: 500; }
.name-cell a:hover { text-decoration: underline; }
.term-cell { color: var(--color-text-light); font-size: 13px; }

/* --- Lists --- */
ul.clean-list { list-style: none; padding: 0; margin: 0; }
ul.clean-list li { margin-bottom: 5px; }

.member-list { list-style: none; padding: 0; margin: 0; }
.member-item { margin-bottom: 5px; }
.rep-list { list-style: none; padding: 0; margin: 0; }
.rep-item { margin-bottom: 4px; }
.rep-item a { color: var(--color-primary); text-decoration: none; font-weight: 500; }

/* --- Career Timeline (Profile) --- */
.career-timeline { border-left: 3px solid var(--color-border); padding-left: 20px; margin-left: 10px; }

.career-item { position: relative; margin-bottom: 30px; }
.career-item::before {
    content: "";
    position: absolute;
    left: -28px;
    top: 5px;
    width: 12px;
    height: 12px;
    background: var(--color-primary);
    border-radius: 50%;
    border: 3px solid white;
}

.congress-num { font-weight: 800; color: var(--color-primary); font-size: 1.2em; margin-bottom: 5px; display: block; }

.details {
    background: var(--color-bg);
    padding: 15px;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
}

.row { display: flex; margin-bottom: 8px; }
.label { width: 150px; font-weight: 600; color: var(--color-text-muted); font-size: 0.9em; }
.value { color: var(--color-text); font-weight: 500; }

.leadership {
    background: var(--color-accent);
    color: var(--color-text);
    font-weight: bold;
    padding: 10px;
    border-radius: 6px;
    margin-top: 10px;
    border: 1px solid var(--color-accent-border);
}

/* --- Back Link --- */
.back-link {
    margin-bottom: 20px;
    display: block;
    color: var(--color-primary);
    text-decoration: none;
    font-weight: bold;
}

/* --- Admin Section (Executive) --- */
.admin-section {
    background: white;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    margin-bottom: 40px;
    overflow: hidden;
}

.admin-header {
    background: var(--color-bg);
    padding: 20px 25px;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.admin-header h2 { margin: 0; font-size: 20px; color: var(--color-primary); }
.admin-meta { color: var(--color-text-muted); font-size: 14px; }

/* --- Search Box (Executive) --- */
.search-box { margin-bottom: 30px; }
.search-box input {
    width: 100%;
    padding: 12px 20px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    font-size: 16px;
    box-sizing: border-box;
}

/* --- Session (Party) --- */
.sessions-list { margin-top: 20px; }

.session-item {
    background: var(--color-bg);
    padding: 15px;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    margin-bottom: 10px;
}

.session-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
}

.session-content {
    display: none;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #ddd;
    font-size: 0.9em;
    column-count: 2;
}

/* --- Members Box (Party) --- */
.members-box { padding: 20px; border-radius: var(--radius-md); border: 1px solid var(--color-border); }
.core-members { background: var(--color-warning-bg); border-color: var(--color-warning-border); }
.influential-members { background: #eefdef; border-color: #a3d6a3; margin-top: 30px; }
.loyalty-score { color: var(--color-success); font-weight: bold; font-size: 0.8em; }

.action-button {
    margin-top: 10px;
    width: 100%;
    padding: 8px;
    cursor: pointer;
    border: 1px solid #ccc;
    background: #f4f4f4;
    border-radius: var(--radius-sm);
}

/* --- District Tags (Province) --- */
.districts-list { margin-bottom: 30px; }
.district-tag {
    display: inline-block;
    padding: 4px 12px;
    background: var(--color-border);
    border-radius: 15px;
    font-size: 13px;
    margin: 0 5px 5px 0;
}

/* --- Grid (Party Profile) --- */
.grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 30px;
}

/* --- Loading Spinner --- */
.loading-spinner {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--color-text-muted);
}

.loading-spinner::after {
    content: "";
    width: 36px;
    height: 36px;
    border: 4px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.loading { text-align: center; padding: 50px; color: var(--color-text-muted); }

/* --- Map (Provinces) --- */
.map-dashboard-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 20px;
}

#map {
    height: 600px;
    width: 100%;
    border-radius: var(--radius-md);
    background: #aadaff;
}

.info {
    padding: 6px 8px;
    font: 14px/16px Arial, Helvetica, sans-serif;
    background: white;
    background: rgba(255, 255, 255, 0.8);
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.2);
    border-radius: 5px;
}

.info h4 { margin: 0 0 5px; color: #777; }

.legend {
    line-height: 18px;
    color: #555;
    background: white;
    padding: 10px;
    border-radius: 5px;
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.2);
}

.legend i {
    width: 18px;
    height: 18px;
    float: left;
    margin-right: 8px;
    opacity: 0.7;
}

/* --- Map Playback --- */
.playback-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}

.play-btn {
    padding: 6px 14px;
    background: var(--color-primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
}

.play-btn:hover { background: var(--color-primary-hover); }

/* --- Responsive --- */
@media (max-width: 768px) {
    .site-nav {
        padding: 12px 20px;
    }

    .nav-links {
        display: none;
        flex-direction: column;
        width: 100%;
        gap: 8px;
        padding-top: 10px;
    }

    .nav-links.open { display: flex; }

    .hamburger { display: block; }

    .nav-search-container {
        margin-left: 0;
        width: 100%;
        order: 99;
    }

    .nav-search-input { width: 100%; }
    .nav-search-input:focus { width: 100%; }

    .search-results-dropdown { width: 100%; left: 0; right: 0; }

    .main-content { padding: 20px; }
    .content { padding-top: 10px; }

    .hero { padding: 50px 20px; }
    .hero h1 { font-size: 28px; }

    .nav-grid { grid-template-columns: 1fr; margin: -20px auto 30px; }
    .nav-card { padding: 25px; }

    .stats-grid { flex-direction: column; gap: 15px; }

    .charts-grid { grid-template-columns: 1fr; }
    .grid { grid-template-columns: 1fr; }
    .grid-3 { grid-template-columns: 1fr; }
    .map-dashboard-grid { grid-template-columns: 1fr; }

    .filters { grid-template-columns: 1fr; }

    .tabs { flex-direction: column; align-items: flex-start; gap: 10px; }
    .tab-buttons { flex-wrap: wrap; }

    .breadcrumb { padding: 8px 20px; }

    #map { height: 350px; }

    .profile-card { padding: 20px; }

    .row { flex-direction: column; }
    .label { width: auto; margin-bottom: 2px; }
}
