/* ========== Amoeba Module Styles ========== */

/* Filter bar */
.amoeba-filter {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.amoeba-filter select,
.amoeba-filter input[type="month"] {
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    background: var(--card-bg);
    color: var(--text);
}

/* Organization tree */
.amoeba-org-tree {
    padding: 8px 0;
}

.amoeba-org-node {
    position: relative;
    padding-left: 24px;
}

.amoeba-org-node::before {
    content: '';
    position: absolute;
    left: 8px;
    top: 0;
    bottom: 0;
    width: 1px;
    background: var(--border);
}

.amoeba-org-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    margin: 4px 0;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: box-shadow 0.2s, border-color 0.2s;
}

.amoeba-org-item:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--primary);
}

.amoeba-org-item-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.amoeba-org-item-name {
    font-weight: 600;
    font-size: 14px;
    color: var(--text);
}

.amoeba-org-item-leader {
    font-size: 12px;
    color: var(--text-secondary);
}

.amoeba-org-item-members {
    font-size: 12px;
    color: var(--text-tertiary);
    background: var(--bg);
    padding: 2px 8px;
    border-radius: 10px;
}

.amoeba-org-actions {
    display: flex;
    gap: 8px;
}

/* Revenue / Cost table */
.amoeba-table-wrap {
    overflow-x: auto;
}

.amoeba-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.amoeba-table th {
    text-align: left;
    padding: 10px 12px;
    background: var(--bg);
    color: var(--text-secondary);
    font-weight: 500;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.amoeba-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
}

.amoeba-table tr:hover td {
    background: var(--bg);
}

.amoeba-amount-positive {
    color: #16a34a;
    font-weight: 600;
}

.amoeba-amount-negative {
    color: #dc2626;
    font-weight: 600;
}

/* Hourly efficiency cards */
.amoeba-hourly-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 16px;
}

.amoeba-hourly-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    transition: box-shadow 0.2s;
}

.amoeba-hourly-card:hover {
    box-shadow: var(--shadow-md);
}

.amoeba-hourly-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.amoeba-hourly-card-name {
    font-weight: 600;
    font-size: 15px;
    color: var(--text);
}

.amoeba-hourly-card-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--primary);
}

.amoeba-hourly-card-unit {
    font-size: 12px;
    color: var(--text-secondary);
    margin-left: 4px;
}

.amoeba-hourly-metrics {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.amoeba-hourly-metric {
    padding: 8px;
    background: var(--bg);
    border-radius: 6px;
}

.amoeba-hourly-metric-label {
    font-size: 11px;
    color: var(--text-tertiary);
    margin-bottom: 4px;
}

.amoeba-hourly-metric-value {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

/* Report section */
.amoeba-report-section {
    margin-bottom: 24px;
}

.amoeba-report-section-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--primary);
    display: inline-block;
}

.amoeba-report-summary {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.amoeba-report-summary-item {
    background: var(--bg);
    border-radius: var(--radius);
    padding: 16px;
    text-align: center;
}

.amoeba-report-summary-label {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.amoeba-report-summary-value {
    font-size: 20px;
    font-weight: 700;
    color: var(--text);
}

/* Settings form */
.amoeba-settings-form {
    max-width: 600px;
}

.amoeba-settings-form .form-group {
    margin-bottom: 16px;
}

.amoeba-settings-form label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 6px;
}

.amoeba-settings-form input,
.amoeba-settings-form select,
.amoeba-settings-form textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    background: var(--card-bg);
    color: var(--text);
}

/* Badge for cost type */
.amoeba-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 500;
}

.amoeba-badge-direct {
    background: #dbeafe;
    color: #2563eb;
}

.amoeba-badge-shared {
    background: #fef3c7;
    color: #d97706;
}

/* Responsive */
@media (max-width: 768px) {
    .amoeba-filter {
        flex-direction: column;
        align-items: stretch;
    }

    .amoeba-hourly-grid {
        grid-template-columns: 1fr;
    }

    .amoeba-report-summary {
        grid-template-columns: 1fr 1fr;
    }
}

/* ========== Database Browser ========== */
.amoeba-browser-layout {
    display: flex;
    gap: 0;
    height: calc(100vh - 120px);
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.amoeba-browser-sidebar {
    width: 280px;
    min-width: 280px;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    background: var(--bg);
}

.amoeba-browser-search {
    padding: 12px;
    border-bottom: 1px solid var(--border);
}

.amoeba-browser-search input {
    width: 100%;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    background: var(--card-bg);
    color: var(--text);
}

.amoeba-browser-table-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 0;
}

.ab-table-item {
    padding: 8px 14px;
    cursor: pointer;
    border-left: 3px solid transparent;
    transition: background 0.15s, border-color 0.15s;
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 4px 8px;
}

.ab-table-item:hover {
    background: var(--card-bg);
}

.ab-table-item.active {
    background: var(--card-bg);
    border-left-color: var(--primary);
}

.ab-table-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    font-family: monospace;
}

.ab-table-comment {
    font-size: 11px;
    color: var(--text-tertiary);
    flex-basis: 100%;
}

.ab-table-rows {
    font-size: 11px;
    color: var(--text-secondary);
    margin-left: auto;
}

/* Main detail area */
.amoeba-browser-main {
    flex: 1;
    overflow: auto;
    display: flex;
    flex-direction: column;
}

.amoeba-browser-placeholder {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-tertiary);
    gap: 12px;
}

.amoeba-browser-placeholder p {
    font-size: 14px;
    margin: 0;
}

/* Detail header */
.ab-detail-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
    gap: 8px;
}

.ab-detail-title strong {
    font-size: 15px;
    color: var(--text);
    font-family: monospace;
}

.ab-detail-comment {
    font-size: 12px;
    color: var(--text-secondary);
    margin-left: 10px;
}

.ab-detail-meta {
    display: flex;
    gap: 12px;
    font-size: 12px;
    color: var(--text-tertiary);
}

/* Tabs */
.ab-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    padding: 0 20px;
}

.ab-tab {
    padding: 10px 16px;
    font-size: 13px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
}

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

.ab-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    font-weight: 500;
}

#amoebaBrowserTabContent {
    padding: 16px 20px;
    flex: 1;
    overflow: auto;
}

.ab-section-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 8px;
}

/* Key badges */
.ab-key-badge {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 600;
    font-family: monospace;
}

.ab-key-pri { background: #fef3c7; color: #92400e; }
.ab-key-uni { background: #dbeafe; color: #1e40af; }
.ab-key-mul { background: #e0e7ff; color: #4338ca; }

/* Data preview toolbar - see enhanced version below */

.ab-data-table td {
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 12px;
    font-family: monospace;
}

.ab-data-table th {
    font-family: monospace;
    font-size: 12px;
}

/* ========== Database Selector (Three-Level Nav) ========== */
.ab-db-selector {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    background: var(--card-bg);
}

.ab-db-selector label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-tertiary);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.ab-db-selector select {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    background: var(--bg);
    color: var(--text);
    cursor: pointer;
}

/* ========== Preview Toolbar Enhanced ========== */
.ab-preview-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    font-size: 13px;
    color: var(--text-secondary);
    flex-wrap: wrap;
    gap: 8px;
}

.ab-preview-tools {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.ab-preview-pager {
    display: flex;
    gap: 8px;
}

.ab-page-size {
    padding: 3px 6px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 12px;
    background: var(--card-bg);
    color: var(--text);
    margin: 0 4px;
}

.ab-tool-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px !important;
    padding: 4px 8px !important;
}

.ab-tool-btn.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.ab-tool-btn svg {
    flex-shrink: 0;
}

/* ========== Field Visibility Panel ========== */
.ab-field-panel {
    position: absolute;
    top: 100%;
    right: 0;
    z-index: 100;
    width: 240px;
    max-height: 360px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg, 0 10px 25px rgba(0,0,0,.12));
    display: flex;
    flex-direction: column;
}

.ab-field-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    font-size: 12px;
}

.ab-field-panel-header strong {
    font-size: 12px;
    color: var(--text);
}

.ab-field-panel-list {
    overflow-y: auto;
    padding: 6px 0;
    max-height: 300px;
}

.ab-field-check {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    font-size: 12px;
    color: var(--text);
    cursor: pointer;
    font-family: monospace;
}

.ab-field-check:hover {
    background: var(--bg);
}

.ab-field-check input[type="checkbox"] {
    width: 14px;
    height: 14px;
    margin: 0;
    cursor: pointer;
}

/* ========== Filter Row ========== */
.ab-filter-row td {
    padding: 4px 6px !important;
    background: var(--bg);
    border-bottom: 2px solid var(--primary);
}

.ab-filter-cell {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 80px;
}

.ab-filter-op {
    width: 100%;
    padding: 2px 4px;
    border: 1px solid var(--border);
    border-radius: 3px;
    font-size: 11px;
    background: var(--card-bg);
    color: var(--text);
}

.ab-filter-val {
    width: 100%;
    padding: 3px 6px;
    border: 1px solid var(--border);
    border-radius: 3px;
    font-size: 11px;
    background: var(--card-bg);
    color: var(--text);
    box-sizing: border-box;
}

.ab-filter-val:focus {
    border-color: var(--primary);
    outline: none;
}

/* ========== Database List in Settings ========== */
.ab-db-list {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.ab-db-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
}

.ab-db-item:last-child {
    border-bottom: none;
}

.ab-db-item:hover {
    background: var(--bg);
}

.ab-db-item-main {
    flex: 1;
    min-width: 0;
}

.ab-db-item-alias {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 2px;
}

.ab-db-item-info {
    font-size: 12px;
    color: var(--text-secondary);
    font-family: monospace;
}

.ab-db-item-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
    margin-left: 12px;
}

/* Database Form */
.ab-db-form {
    margin-top: 16px;
    padding: 20px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.ab-db-form .form-group {
    margin-bottom: 12px;
}

.ab-db-form label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 4px;
}

.ab-db-form input,
.ab-db-form select {
    width: 100%;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    background: var(--card-bg);
    color: var(--text);
    box-sizing: border-box;
}

/* Button helpers */
.btn-xs {
    padding: 2px 6px !important;
    font-size: 11px !important;
}

/* Browser responsive */
@media (max-width: 768px) {
    .amoeba-browser-layout {
        flex-direction: column;
        height: auto;
    }
    .amoeba-browser-sidebar {
        width: 100%;
        min-width: auto;
        max-height: 260px;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    .ab-preview-toolbar {
        flex-direction: column;
        align-items: flex-start;
    }
    .ab-field-panel {
        right: auto;
        left: 0;
    }
}

/* ========== Dashboard Layout: Secondary Nav + Content ========== */
.amoeba-dash-layout {
    display: flex;
    height: calc(100vh - 120px);
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.amoeba-dash-nav {
    width: 140px;
    min-width: 140px;
    border-right: 1px solid var(--border);
    background: var(--bg);
    padding: 8px 0;
    overflow-y: auto;
}

.amoeba-dash-nav-item {
    padding: 10px 14px;
    font-size: 13px;
    cursor: pointer;
    border-left: 3px solid transparent;
    color: var(--text-secondary);
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    user-select: none;
}

.amoeba-dash-nav-item:hover {
    background: var(--card-bg);
    color: var(--text);
}

.amoeba-dash-nav-item.active {
    background: var(--card-bg);
    border-left-color: var(--primary);
    color: var(--primary);
    font-weight: 500;
}

.amoeba-dash-content {
    flex: 1;
    overflow: auto;
    padding: 0;
}

.amoeba-dash-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
}

/* ========== Profit Overview ========== */
.amoeba-profit-wrap {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 14px;
    box-sizing: border-box;
}

.amoeba-profit-filter {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    flex-wrap: wrap;
    flex-shrink: 0;
}

.amoeba-profit-filter label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    white-space: nowrap;
}

.amoeba-profit-filter input[type="date"],
.amoeba-profit-filter select {
    padding: 5px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    background: var(--card-bg);
    color: var(--text);
}

.amoeba-profit-filter span {
    color: var(--text-secondary);
    font-size: 13px;
}

/* Left-right split panels */
.amoeba-profit-panels {
    display: flex;
    gap: 12px;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.amoeba-profit-left {
    flex: 0 0 46%;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    max-height: 400px;
}

.amoeba-profit-right {
    flex: 1;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    max-height: 400px;
}

.amoeba-profit-panel-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    flex-shrink: 0;
}

.amoeba-profit-left .amoeba-table-wrap,
.amoeba-profit-right .amoeba-table-wrap {
    flex: 1;
    overflow: auto;
    min-height: 0;
}

/* Body containers inside profit panels: complete the flex chain */
.amoeba-profit-left > div:not(.amoeba-profit-panel-title),
.amoeba-profit-right > div:not(.amoeba-profit-panel-title) {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

/* Profit table */
.amoeba-profit-table {
    font-size: 12px;
}

.amoeba-profit-table th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--bg);
    font-size: 12px;
    padding: 8px 10px;
    white-space: nowrap;
}

.amoeba-profit-table td {
    padding: 7px 10px;
    font-size: 12px;
}

.amoeba-profit-row-clickable {
    cursor: pointer;
    transition: background 0.1s;
}

.amoeba-profit-row-clickable:hover {
    background: var(--bg);
}

.amoeba-profit-row-active {
    background: #eff6ff !important;
}

.amoeba-profit-total-row td {
    background: var(--bg);
    border-top: 2px solid var(--border);
    position: sticky;
    bottom: 0;
    z-index: 1;
}

.amoeba-profit-goods-cell {
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Pagination */
.amoeba-profit-pager {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px;
    border-top: 1px solid var(--border);
    background: var(--bg);
    flex-shrink: 0;
    flex-wrap: wrap;
    gap: 6px;
}

.amoeba-profit-pager-info {
    font-size: 12px;
    color: var(--text-secondary);
}

.amoeba-profit-pager-btns {
    display: flex;
    gap: 6px;
}

/* Responsive */
@media (max-width: 1024px) {
    .amoeba-profit-panels {
        flex-direction: column;
    }
    .amoeba-profit-left {
        flex: none;
        max-height: 45%;
    }
    .amoeba-profit-right {
        flex: 1;
    }
}

@media (max-width: 768px) {
    .amoeba-dash-layout {
        flex-direction: column;
        height: auto;
    }
    .amoeba-dash-nav {
        width: 100%;
        min-width: auto;
        display: flex;
        overflow-x: auto;
        padding: 0;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    .amoeba-dash-nav-item {
        white-space: nowrap;
        border-left: none;
        border-bottom: 3px solid transparent;
        padding: 8px 14px;
    }
    .amoeba-dash-nav-item.active {
        border-left: none;
        border-bottom-color: var(--primary);
    }
    .amoeba-profit-filter {
        flex-direction: column;
        align-items: stretch;
    }
}
