:root {
    --bg: #f5f7fa;
    --surface: #ffffff;
    --surface-hover: #f0f2f5;
    --border: #e1e4e8;
    --text: #333333;
    --text-dim: #888888;
    --accent: #ff9900;
    --accent-glow: rgba(255, 153, 0, 0.12);
    --accent-text: #232f3e;
    --danger: #dc3545;
    --danger-bg: #ffeef0;
    --green: #28a745;
    --green-bg: #e6ffed;
    --orange: #e36209;
    --orange-bg: #fff5e6;
    --radius: 10px;
    --transition: 200ms ease-out;
}

[data-theme="dark"] {
    --bg: #0f1117;
    --surface: #1a1d27;
    --surface-hover: #1f2333;
    --border: #2a2d3a;
    --text: #e1e4ed;
    --text-dim: #8b8fa3;
    --accent: #ff9900;
    --accent-glow: rgba(255, 153, 0, 0.12);
    --accent-text: #ffffff;
    --danger: #ff6c8c;
    --danger-bg: rgba(255, 108, 140, 0.12);
    --green: #4ade80;
    --green-bg: rgba(74, 222, 128, 0.12);
    --orange: #fb923c;
    --orange-bg: rgba(251, 146, 60, 0.12);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    line-height: 1.6;
    transition: background-color var(--transition), color var(--transition);
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px;
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24px 28px;
    background: var(--surface);
    border-radius: 16px;
    border: 1px solid var(--border);
    margin-bottom: 24px;
    transition: background var(--transition), border-color var(--transition);
}

header h1 {
    font-size: 1.6rem;
    color: var(--text);
    font-weight: 700;
    letter-spacing: -0.02em;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.health-status {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 18px;
    background: var(--surface-hover);
    border-radius: 24px;
    font-size: 0.88rem;
    color: var(--text-dim);
    transition: background var(--transition), color var(--transition);
}

.status-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--text-dim);
    transition: background 0.3s ease;
}

.status-indicator.healthy {
    background: var(--green);
    box-shadow: 0 0 6px rgba(40, 167, 69, 0.4);
}

[data-theme="dark"] .status-indicator.healthy {
    box-shadow: 0 0 6px rgba(74, 222, 128, 0.4);
}

.status-indicator.error {
    background: var(--danger);
    box-shadow: 0 0 6px rgba(220, 53, 69, 0.4);
}

/* Theme Toggle */
.theme-toggle {
    width: 38px;
    height: 38px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-hover);
    color: var(--text-dim);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    transition: all var(--transition);
}

.theme-toggle:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-glow);
}

.theme-toggle .icon-sun,
.theme-toggle .icon-moon {
    display: none;
}

.theme-toggle .icon-sun {
    display: block;
}

[data-theme="dark"] .theme-toggle .icon-sun {
    display: none;
}

[data-theme="dark"] .theme-toggle .icon-moon {
    display: block;
}

/* Tabs — bottom border line style */
.tabs {
    display: flex;
    gap: 0;
    margin-bottom: 0;
    padding: 0;
    border-bottom: 1px solid var(--border);
}

.tab {
    padding: 12px 28px;
    border: none;
    background: transparent;
    color: var(--text-dim);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all var(--transition);
    margin-bottom: -1px;
}

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

.tab.active {
    color: var(--accent);
    border-bottom: 2px solid var(--accent);
}

/* Tab Content */
.tab-content {
    display: none;
    background: var(--surface);
    padding: 28px;
    border-radius: 0 0 16px 16px;
    border: 1px solid var(--border);
    border-top: none;
    transition: background var(--transition), border-color var(--transition);
    animation: fadeIn 0.2s ease-out;
}

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

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

/* Filters */
.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: flex-end;
    margin-bottom: 24px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
}

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

#refreshEvents,
#refreshResources {
    margin-left: auto;
}

.date-toggle-row {
    margin-bottom: 24px;
}

.btn-date-toggle {
    padding: 6px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-hover);
    color: var(--text-dim);
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-date-toggle:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.events-date-range {
    display: none;
    gap: 12px;
    align-items: flex-end;
    margin-top: 12px;
}

.events-date-range.open {
    display: flex;
}

.events-date-range input[type="datetime-local"] {
    padding: 8px 12px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.85rem;
    background: var(--surface-hover);
    color: var(--text);
    transition: all var(--transition);
}

.events-date-range input[type="datetime-local"]:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.filter-group label {
    font-size: 0.82rem;
    color: var(--text-dim);
    font-weight: 500;
}

.filter-group input,
.filter-group select {
    padding: 10px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.92rem;
    min-width: 180px;
    background: var(--surface-hover);
    transition: all var(--transition);
    color: var(--text);
}

.filter-group input:focus,
.filter-group select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
    background: var(--surface);
}

.filter-group input::placeholder {
    color: var(--text-dim);
}

/* Buttons */
.btn {
    padding: 10px 22px;
    border: none;
    border-radius: var(--radius);
    font-size: 0.92rem;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-primary {
    background: var(--accent);
    color: var(--accent-text);
    font-weight: 600;
    box-shadow: 0 2px 8px var(--accent-glow);
}

.btn-primary:hover {
    filter: brightness(1.1);
    box-shadow: 0 4px 14px var(--accent-glow);
    transform: translateY(-1px);
}

.btn-primary:active {
    transform: translateY(0);
    box-shadow: 0 1px 4px var(--accent-glow);
}

.btn-secondary {
    background: var(--surface-hover);
    color: var(--text-dim);
    border: 1.5px solid var(--border);
    font-weight: 500;
}

.btn-secondary:hover {
    border-color: var(--text-dim);
    color: var(--text);
}

.btn-danger {
    background: var(--danger-bg);
    color: var(--danger);
    font-weight: 600;
}

.btn-danger:hover {
    background: var(--danger);
    color: #fff;
}

.btn-sm {
    padding: 6px 14px;
    font-size: 0.82rem;
    border-radius: 8px;
}

.btn-icon {
    width: 38px;
    height: 38px;
    padding: 0;
    background: var(--surface-hover);
    border: 1.5px solid var(--border);
    color: var(--text-dim);
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-glow);
}

/* Results */
.results {
    min-height: 200px;
}

.placeholder {
    text-align: center;
    color: var(--text-dim);
    padding: 60px 20px;
    font-size: 0.95rem;
}

/* Tables */
.events-table,
.resources-table,
.groups-table {
    width: 100%;
    table-layout: fixed;
    border-collapse: separate;
    border-spacing: 0;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--border);
}

/* Events: Time Region Service Action Target Priority */
.events-table th:nth-child(1),
.events-table td:nth-child(1) { width: 16%; }
.events-table th:nth-child(2),
.events-table td:nth-child(2) { width: 13%; }
.events-table th:nth-child(3),
.events-table td:nth-child(3) { width: 10%; }
.events-table th:nth-child(4),
.events-table td:nth-child(4) { width: 22%; }
.events-table th:nth-child(5),
.events-table td:nth-child(5) { width: 27%; }
.events-table th:nth-child(6),
.events-table td:nth-child(6) { width: 12%; }

.events-table td,
.resources-table td {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Resources: Group Service Resource ID State Details Modified By Modified */
.resources-table th:nth-child(1),
.resources-table td:nth-child(1) { width: 11%; }
.resources-table th:nth-child(2),
.resources-table td:nth-child(2) { width: 10%; }
.resources-table th:nth-child(3),
.resources-table td:nth-child(3) { width: 22%; }
.resources-table th:nth-child(4),
.resources-table td:nth-child(4) { width: 10%; }
.resources-table th:nth-child(5),
.resources-table td:nth-child(5) { width: 16%; }
.resources-table th:nth-child(6),
.resources-table td:nth-child(6) { width: 14%; }
.resources-table th:nth-child(7),
.resources-table td:nth-child(7) { width: 17%; }

.events-table th,
.events-table td,
.resources-table th,
.resources-table td,
.groups-table th,
.groups-table td {
    padding: 13px 16px;
    text-align: left;
}

.events-table th,
.resources-table th,
.groups-table th {
    background: var(--surface-hover);
    font-weight: 600;
    font-size: 0.82rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    border-bottom: 1.5px solid var(--border);
}

.events-table td,
.resources-table td,
.groups-table td {
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}

.events-table tbody tr,
.resources-table tbody tr,
.groups-table tbody tr {
    transition: background var(--transition);
}

.events-table tbody tr:hover,
.resources-table tbody tr:hover,
.groups-table tbody tr:hover {
    background: var(--accent-glow);
}

.events-table tbody tr:last-child td,
.resources-table tbody tr:last-child td,
.groups-table tbody tr:last-child td {
    border-bottom: none;
}

/* Badges */
.priority-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.priority-high {
    background: var(--danger-bg);
    color: var(--danger);
}

.priority-medium {
    background: var(--orange-bg);
    color: var(--orange);
}

.priority-low {
    background: var(--green-bg);
    color: var(--green);
}

.service-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.78rem;
    font-weight: 500;
}

.service-iam {
    background: rgba(13, 110, 253, 0.1);
    color: #6c8cff;
}

.service-ec2 {
    background: var(--green-bg);
    color: var(--green);
}

.service-rds {
    background: var(--orange-bg);
    color: var(--orange);
}

.service-dynamodb {
    background: rgba(13, 110, 253, 0.1);
    color: #6c8cff;
}

.service-s3 {
    background: rgba(155, 89, 182, 0.12);
    color: #b07cc6;
}

.service-lambda {
    background: rgba(255, 153, 0, 0.12);
    color: #ff9900;
}

.state-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 600;
}

.state-running {
    background: var(--green-bg);
    color: var(--green);
}

.state-stopped {
    background: var(--danger-bg);
    color: var(--danger);
}

.state-pending {
    background: var(--orange-bg);
    color: var(--orange);
}

.tag-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    background: rgba(99, 102, 241, 0.12);
    color: #818cf8;
    margin-right: 4px;
}

.region-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 16px;
    font-size: 0.75rem;
    font-weight: 500;
    background: rgba(13, 110, 253, 0.1);
    color: #6c8cff;
    margin: 2px 4px 2px 0;
}

.resource-id {
    font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
    font-size: 0.82rem;
    background: var(--surface-hover);
    padding: 3px 8px;
    border-radius: 6px;
    color: var(--text-dim);
    transition: background var(--transition), color var(--transition);
}

/* Summary Cards */
.summary {
    display: flex;
    gap: 16px;
    margin-bottom: 24px;
}

.summary-card {
    background: var(--surface);
    padding: 18px 24px;
    border-radius: 14px;
    flex: 1;
    text-align: center;
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    transition: background var(--transition), border-color var(--transition);
}

.summary-card .count {
    font-size: 2rem;
    font-weight: 700;
    color: var(--accent);
    line-height: 1.2;
}

.summary-card .label {
    font-size: 0.82rem;
    color: var(--text-dim);
    margin-top: 2px;
}

/* Dashboard Controls */
.dashboard-controls {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 24px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
}

.dashboard-presets {
    display: flex;
    gap: 4px;
    background: var(--surface-hover);
    padding: 4px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.btn-preset {
    padding: 7px 18px;
    border: none;
    border-radius: 7px;
    background: transparent;
    color: var(--text-dim);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
}

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

.btn-preset.active {
    background: var(--accent);
    color: var(--accent-text);
    box-shadow: 0 1px 4px var(--accent-glow);
}

.dashboard-date-range {
    display: flex;
    align-items: flex-end;
    gap: 12px;
}

.dashboard-date-range input[type="datetime-local"] {
    padding: 8px 12px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.85rem;
    background: var(--surface-hover);
    color: var(--text);
    transition: all var(--transition);
}

.dashboard-date-range input[type="datetime-local"]:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

/* Overview Cards */
.overview-cards {
    display: flex;
    gap: 16px;
    margin-bottom: 24px;
}

.overview-card {
    flex: 1;
    background: var(--surface-hover);
    padding: 20px 24px;
    border-radius: 14px;
    text-align: center;
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    transition: background var(--transition), border-color var(--transition);
}

.overview-value {
    font-size: 2.2rem;
    font-weight: 700;
    color: var(--accent);
    line-height: 1.2;
}

.overview-label {
    font-size: 0.82rem;
    color: var(--text-dim);
    margin-top: 4px;
}

/* Alert Section */
.alert-section {
    background: rgba(220, 38, 38, 0.08);
    border: 1px solid rgba(220, 38, 38, 0.3);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 20px;
}

.alert-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}

.alert-icon {
    font-size: 1.2rem;
    color: #dc2626;
}

.alert-title {
    font-weight: 700;
    font-size: 0.95rem;
    color: #dc2626;
}

.alert-count {
    background: #dc2626;
    color: #fff;
    font-size: 0.75rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 10px;
    min-width: 20px;
    text-align: center;
}

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

.alert-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    background: var(--surface);
    border-radius: 6px;
    font-size: 0.85rem;
    border-left: 3px solid #dc2626;
}

.alert-time {
    color: var(--text-dim);
    white-space: nowrap;
    min-width: 80px;
}

.alert-group {
    font-weight: 600;
    color: var(--text);
    min-width: 60px;
}

.alert-action {
    color: #dc2626;
    font-weight: 600;
    flex: 1;
}

.alert-target {
    font-family: 'SF Mono', 'Consolas', monospace;
    font-size: 0.8rem;
    color: var(--text-secondary);
    flex: 1;
}

.alert-user {
    color: var(--text-dim);
    min-width: 80px;
    text-align: right;
}

/* Dashboard Grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.chart-card {
    background: var(--surface-hover);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 20px 24px;
    transition: background var(--transition), border-color var(--transition);
}

.chart-card h3 {
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 16px;
}

.chart-card canvas {
    width: 100% !important;
    max-height: 280px;
}

/* Group Cloud */
.group-cloud {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 12px 20px;
    min-height: 120px;
    padding: 16px 8px;
}

.group-cloud-empty {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.group-tag {
    font-weight: 700;
    cursor: default;
    transition: transform 0.15s;
    line-height: 1.2;
}

.group-tag:hover {
    transform: scale(1.12);
}

/* Group Form */
.group-form h3 {
    font-size: 1rem;
    color: var(--text);
    margin-bottom: 16px;
    font-weight: 600;
}

/* Loading */
.loading {
    text-align: center;
    padding: 48px;
    color: var(--text-dim);
    font-size: 0.92rem;
}

.loading::after {
    content: '';
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-left: 10px;
    vertical-align: middle;
}

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

/* Error */
.error-message {
    background: var(--danger-bg);
    color: var(--danger);
    padding: 18px 24px;
    border-radius: 12px;
    text-align: center;
    font-size: 0.92rem;
}

/* Footer */
footer {
    text-align: center;
    padding: 36px 0;
    color: var(--text-dim);
    font-size: 0.82rem;
}

/* Event Detail Modal */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    align-items: center;
    justify-content: center;
}

.modal-overlay.active {
    display: flex;
}

.modal-content {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    max-width: 560px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    padding: 28px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.3);
    animation: fadeIn 0.2s ease-out;
}

.modal-content h3 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 32px;
    height: 32px;
    border: none;
    background: var(--surface-hover);
    color: var(--text-dim);
    border-radius: 8px;
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}

.modal-close:hover {
    background: var(--danger-bg);
    color: var(--danger);
}

/* Modal sections */
.modal-sections {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.modal-section {
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.modal-section:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.modal-section-title {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 10px;
}

.modal-fields {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.modal-field-row {
    display: flex;
    align-items: baseline;
    padding: 8px 12px;
    border-radius: 8px;
}

.modal-field-row:nth-child(odd) {
    background: var(--surface-hover);
}

.modal-field-row dt {
    width: 100px;
    flex-shrink: 0;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.modal-field-row dd {
    flex: 1;
    font-size: 0.9rem;
    color: var(--text);
    word-break: break-all;
}

.modal-field-row dd code {
    font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
    font-size: 0.84rem;
    background: var(--surface-hover);
    padding: 2px 8px;
    border-radius: 6px;
    color: var(--text-dim);
}

.modal-field-row:nth-child(odd) dd code {
    background: var(--surface);
}

.modal-description {
    color: var(--accent);
    font-weight: 500;
    font-size: 0.85rem;
}

/* Clickable table rows */
.events-table tbody tr,
.resources-table tbody tr {
    cursor: pointer;
}

/* Responsive */
@media (max-width: 768px) {
    .container {
        padding: 16px;
    }

    header {
        flex-direction: column;
        gap: 12px;
        text-align: center;
        padding: 20px;
    }

    .header-actions {
        width: 100%;
        justify-content: center;
    }

    .filters {
        flex-direction: column;
        align-items: stretch;
    }

    .filter-group input,
    .filter-group select {
        min-width: auto;
        width: 100%;
    }

    .summary {
        flex-direction: column;
    }

    .overview-cards {
        flex-direction: column;
    }

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

    .events-table,
    .resources-table,
    .groups-table {
        font-size: 0.82rem;
    }

    .events-table th,
    .events-table td,
    .resources-table th,
    .resources-table td,
    .groups-table th,
    .groups-table td {
        padding: 10px 12px;
    }

    .tab-content {
        padding: 20px;
    }

    .tabs {
        overflow-x: auto;
    }
}
