:root {
    --bg: #f6f7fb;
    --card: #fff;
    --text: #111827;
    --muted: #6b7280;
    --border: #e5e7eb;
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --danger: #dc2626;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: "Segoe UI", Tahoma, sans-serif;
    color: var(--text);
    background: var(--bg);
}

.topbar {
    position: sticky;
    top: 0;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    z-index: 10;
}

.topbar__inner {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 12px 16px;
}

.logo {
    font-weight: 700;
    text-decoration: none;
    color: var(--text);
}

.nav {
    display: flex;
    gap: 12px;
    margin-right: auto;
}

.nav a {
    text-decoration: none;
    color: var(--muted);
    font-weight: 600;
}

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

.logout button {
    background: transparent;
    border: 1px solid var(--border);
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
}

.page {
    max-width: 1600px;
    margin: 0 auto;
    padding: 24px 16px 48px;
}

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px;
}

.table {
    width: 100%;
    border-collapse: collapse;
}

.table th,
.table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    text-align: left;
}

.table th {
    background: #f3f4f6;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    position: sticky;
    top: 0;
    z-index: 2;
}
.table tr.is-active td {
    background: #eef2ff;
    border-bottom-color: #c7d2fe;
}

.company-panel-shell {
    position: relative;
    background: #ffffff;
    border: 2px solid #c7d2fe;
    border-radius: 10px;
    box-shadow: 0 8px 20px rgba(79, 70, 229, 0.1);
    padding: 12px;
    max-width: 1080px;
}

.company-panel-shell::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 5px;
    border-radius: 10px 0 0 10px;
    background: linear-gradient(180deg, #4f46e5 0%, #6366f1 100%);
}

.company-row-main {
    display: flex;
    align-items: center;
    gap: 10px;
}

.company-row-left {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.company-row-name {
    font-weight: 600;
}

.company-merged-pill {
    padding: 2px 6px;
    border-radius: 999px;
    background: #fef3c7;
    color: #92400e;
    font-size: 11px;
}

.company-legacy-pill {
    padding: 2px 7px;
    border-radius: 999px;
    background: #ffedd5;
    color: #9a3412;
    font-size: 11px;
    font-weight: 700;
    border: 1px solid #fed7aa;
}

.company-unbilled-pill {
    padding: 2px 7px;
    border-radius: 999px;
    background: #fee2e2;
    color: #991b1b;
    font-size: 11px;
    font-weight: 700;
    border: 1px solid #fecaca;
}

.company-row-meta {
    color: var(--muted);
    font-size: 12px;
}

.company-row-caret {
    margin-left: auto;
    width: 9px;
    height: 9px;
    border-right: 2px solid #9ca3af;
    border-bottom: 2px solid #9ca3af;
    transform: rotate(45deg);
    transition: transform 0.15s ease, border-color 0.15s ease;
}

.table tr.is-active .company-row-caret {
    transform: rotate(225deg);
    border-color: #4f46e5;
}

.table tr[data-company-row] {
    cursor: pointer;
}

.table tr[data-company-row]:focus-visible td {
    outline: 2px solid #a5b4fc;
    outline-offset: -2px;
}

.company-panel-tabs-wrap {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 10px;
}

.company-panel-title {
    font-weight: 700;
}

.company-panel-tabs {
    display: inline-flex;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    background: #fff;
}

.company-panel-tab {
    border: 0;
    border-right: 1px solid var(--border);
    background: #fff;
    color: var(--muted);
    padding: 7px 11px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

.company-panel-tab:last-child {
    border-right: 0;
}

.company-panel-tab:hover {
    background: #f8fafc;
    color: var(--text);
}

.company-panel-tab.active {
    background: #4f46e5;
    color: #fff;
}

.button {
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 8px 14px;
    cursor: pointer;
}

.button:hover { background: var(--primary-hover); }

.button--danger {
    background: var(--danger);
}
.button--secondary {
    background: #fff;
    color: var(--text);
    border: 1px solid var(--border);
}
.button--secondary:hover {
    background: #f3f4f6;
}

.button-link {
    border: 0;
    background: transparent;
    padding: 0;
    margin: 0;
    color: var(--primary);
    font: inherit;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.button-link:hover {
    color: var(--primary-hover);
}

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.35);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
    z-index: 50;
}

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

.modal-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    max-width: 520px;
    width: 100%;
    padding: 16px;
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.2);
    max-height: 80vh;
    overflow: auto;
    text-align: left;
}

.modal-card--reply {
    max-width: 920px;
}

.modal-card--reply textarea[name="body"] {
    min-height: 380px;
    resize: vertical;
}

.reply-editor-toolbar {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}

.reply-editor-toolbar .button {
    padding: 6px 10px;
    font-size: 12px;
}

.reply-editor {
    min-height: 380px;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px;
    overflow: auto;
    background: #fff;
}

.reply-editor:focus {
    outline: 2px solid rgba(79, 70, 229, 0.2);
    border-color: #818cf8;
}

.reply-editor-help {
    margin-top: 6px;
    font-size: 12px;
    color: var(--muted);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.modal-header h3 {
    margin: 0;
    font-size: 16px;
}

.modal-close {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 4px 8px;
    cursor: pointer;
}

.pagination {
    display: inline-flex;
    gap: 6px;
    flex-wrap: wrap;
    align-items: center;
}

.pagination a,
.pagination span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 28px;
    padding: 0 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    text-decoration: none;
    color: var(--muted);
    font-size: 12px;
    background: #fff;
}

.pagination a:hover {
    color: var(--text);
    border-color: #cbd5f5;
}

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

.pagination .disabled {
    opacity: 0.5;
    pointer-events: none;
}

.form-group { margin-bottom: 16px; }
.checkbox-row {
    display: flex;
    align-items: flex-start;
    justify-content: flex-start;
    gap: 8px;
}
.checkbox-row input[type="checkbox"] {
    margin-top: 3px;
}

input, select, textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
}

.notice { padding: 10px 12px; border-radius: 6px; margin-bottom: 12px; }
.notice--error { background: #fee2e2; color: #991b1b; }
.notice--success { background: #dcfce7; color: #166534; }

.split {
    display: grid;
    grid-template-columns: 1.15fr 1fr;
    gap: 16px;
}

@media (max-width: 900px) {
    .split { grid-template-columns: 1fr; }
    .nav { display: none; }
}

.company-edit-head {
    margin-bottom: 12px;
}

.company-edit-head h3 {
    margin: 0;
    font-size: 20px;
}

.company-edit-head p {
    margin: 6px 0 0;
    color: var(--muted);
    font-size: 13px;
}

.company-edit-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.company-edit-section {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px;
    background: #fff;
}

.company-edit-section h4 {
    margin: 0 0 12px;
    font-size: 15px;
}

.company-edit-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.company-edit-span-2 {
    grid-column: span 2;
}

.company-edit-help {
    font-size: 12px;
    color: var(--muted);
    margin-top: 6px;
}

.company-edit-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding-top: 8px;
}

.company-danger {
    border: 1px solid #fecaca;
    background: #fff7f7;
    border-radius: 10px;
    padding: 14px;
    margin-top: 14px;
}

.company-danger h4 {
    margin: 0 0 8px;
    color: #991b1b;
    font-size: 15px;
}

.company-danger p {
    margin: 0 0 10px;
    color: #7f1d1d;
    font-size: 13px;
}

.company-danger-options {
    display: grid;
    gap: 10px;
}

.company-danger-options label {
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

.company-danger-options select {
    max-width: 420px;
}

.company-danger-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 10px;
}

@media (max-width: 760px) {
    .company-edit-grid {
        grid-template-columns: 1fr;
    }

    .company-edit-span-2 {
        grid-column: span 1;
    }
}
