
:root {
    --bg: #f6f6f6;
    --surface: #ffffff;
    --text: #171717;
    --muted: #808080;
    --border: #e1e1e1;
    --accent: #171717;
    --inverse: #ffffff;
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    background: var(--bg);
    color: var(--text);
}

body.dark {
    --bg: #111111;
    --surface: #1b1b1b;
    --text: #f1f1f1;
    --muted: #999999;
    --border: #333333;
    --accent: #eeeeee;
    --inverse: #111111;
}

button, input, select {
    font: inherit;
    color: var(--text);
}

button {
    cursor: pointer;
    border: 1px solid var(--border);
    background: var(--surface);
    padding: 12px 16px;
    border-radius: 5px;
}

button:hover {
    opacity: .8;
}

input, select {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 5px;
    padding: 14px;
    min-width: 0;
}

input:focus, select:focus {
    outline: 1px solid var(--muted);
}

.eyebrow {
    font-size: 10px;
    letter-spacing: 2px;
    font-weight: 600;
    color: var(--muted);
}

/* LOGIN */

#login-screen {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 1fr 1fr;
}

.login-brand {
    position: relative;
    background: #151515;
    color: white;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 10%;
}

.login-brand h1 {
    font-size: clamp(55px, 9vw, 130px);
    line-height: .9;
    letter-spacing: -5px;
    margin: 35px 0;
}

.login-brand p {
    color: #aaa;
    font-size: 21px;
    line-height: 1.5;
}

.brand-footer {
    position: absolute;
    bottom: 30px;
    font-size: 10px;
    letter-spacing: 2px;
    color: #777;
}

.login-area {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 35px;
    background: var(--surface);
}

#login-form {
    width: 100%;
    max-width: 360px;
}

#login-form h2 {
    font-size: 36px;
    letter-spacing: -1.5px;
    margin: 20px 0 10px;
}

#login-form p {
    color: var(--muted);
    font-size: 14px;
    margin-bottom: 35px;
}

#login-form label {
    display: block;
    font-size: 13px;
    margin: 20px 0 8px;
}

#login-form input {
    width: 100%;
}

#login-button {
    width: 100%;
    background: var(--accent);
    color: var(--inverse);
    margin-top: 25px;
    padding: 15px;
}

#login-form small {
    color: var(--muted);
    font-size: 11px;
}

#login-error, #dashboard-error {
    color: #d45c5c !important;
    font-size: 13px;
}

/* DASHBOARD */

#dashboard {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
}

.sidebar {
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 30px 20px;
    display: flex;
    flex-direction: column;
}

.sidebar h2 {
    font-size: 20px;
    letter-spacing: -1px;
    margin: 0 0 8px;
}

nav {
    margin-top: 60px;
}

.nav-label {
    display: block;
    font-size: 10px;
    letter-spacing: 2px;
    color: var(--muted);
    margin-bottom: 15px;
}

nav button {
    width: 100%;
    text-align: left;
    font-size: 13px;
}

.nav-active {
    background: var(--accent);
    color: var(--inverse);
}

.account {
    margin-top: auto;
    padding-top: 40px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.account span {
    font-size: 12px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 1px;
}

main {
    padding: 25px 35px;
    min-width: 0;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    font-size: 12px;
    color: var(--muted);
}

header button {
    font-size: 11px;
}

.page-heading {
    margin: 45px 0 30px;
}

.page-heading h1 {
    font-size: 36px;
    letter-spacing: -1.5px;
    margin: 12px 0;
}

.page-heading p {
    color: var(--muted);
    font-size: 14px;
}

.stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
}

.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 20px;
}

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

.stat strong {
    display: block;
    font-size: 36px;
    font-weight: 500;
    margin-top: 15px;
}

.toolbar {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin: 35px 0 15px;
}

.toolbar input {
    flex: 1;
}

.table-container {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    white-space: nowrap;
}

th {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--muted);
}

td, th {
    padding: 18px;
    border-bottom: 1px solid var(--border);
}

td {
    font-size: 13px;
}

tbody tr {
    cursor: pointer;
}

tbody tr:hover {
    background: var(--bg);
}

.status {
    font-size: 11px;
    text-transform: capitalize;
    padding: 5px 9px;
    border-radius: 4px;
}

.status.active {
    color: #398763;
    background: #39876318;
}

.status.review {
    color: #b48b3d;
    background: #b48b3d18;
}

.status.inactive {
    color: #bb6262;
    background: #bb626218;
}

#agency-detail {
    margin-top: 20px;
    padding: 25px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow-wrap: anywhere;
}

.contact-card {
    border-top: 1px solid var(--border);
    margin-top: 15px;
    padding-top: 15px;
    font-size: 14px;
    line-height: 1.7;
}

/* RESPONSIVE */

@media (max-width: 760px) {
    #login-screen {
        grid-template-columns: 1fr;
    }

    .login-brand {
        padding: 35px;
    }

    .login-brand h1 {
        margin: 20px 0;
        font-size: 55px;
        letter-spacing: -2px;
    }

    .brand-footer {
        display: none;
    }

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

    .sidebar {
        border-right: 0;
        border-bottom: 1px solid var(--border);
    }

    nav {
        margin-top: 20px;
    }

    .account {
        padding-top: 20px;
    }

    main {
        padding: 20px;
    }

    .stats {
        gap: 8px;
    }

    .stat {
        padding: 12px;
    }

    .stat strong {
        font-size: 28px;
    }
}

/* MANAGEMENT PANELS */

nav button {
    margin-bottom: 8px;
}

.management-card {
    padding: 22px;
    margin-bottom: 15px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
}

.management-card h3 {
    margin: 0 0 10px;
}

.management-card p {
    color: var(--muted);
    font-size: 13px;
}

.permission-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

.permission-row:last-child {
    border-bottom: 0;
}

.permission-row input {
    appearance: none;
    width: 42px;
    height: 24px;
    border-radius: 30px;
    background: #aaa;
    border: none;
    padding: 0;
    position: relative;
    cursor: pointer;
}

.permission-row input:checked {
    background: #398763;
}

.permission-row input::after {
    content: "";
    position: absolute;
    width: 18px;
    height: 18px;
    left: 3px;
    top: 3px;
    border-radius: 50%;
    background: white;
    transition: .15s;
}

.permission-row input:checked::after {
    left: 21px;
}

.permission-row input:disabled {
    opacity: .5;
    cursor: wait;
}

.audit-event {
    padding: 18px 0;
    border-bottom: 1px solid var(--border);
    overflow-wrap: anywhere;
}

.audit-event pre {
    white-space: pre-wrap;
    font-size: 12px;
    color: var(--muted);
}

.audit-event small {
    color: var(--muted);
}

#management-message {
    color: #398763;
    font-size: 13px;
}

/* AGENCY EDITOR */

#add-agency-button,
.primary-button {
    background: var(--accent);
    color: var(--inverse);
}

.editor-dialog {
    width: calc(100% - 40px);
    max-width: 620px;
    max-height: 90vh;
    overflow-y: auto;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 30px;
}

.editor-dialog::backdrop {
    background: rgba(0, 0, 0, .55);
    backdrop-filter: blur(4px);
}

.editor-dialog h2 {
    font-size: 28px;
    letter-spacing: -1px;
    margin: 12px 0 25px;
}

.editor-fields {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
}

.editor-field {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
}

.editor-field.full {
    grid-column: 1 / -1;
}

.editor-field label {
    font-size: 12px;
    color: var(--muted);
}

.editor-field textarea {
    font: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 5px;
    padding: 14px;
    min-height: 100px;
    resize: vertical;
}

.editor-actions {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    margin-top: 25px;
}

.editor-error {
    color: #d45c5c;
    font-size: 13px;
}

@media (max-width: 500px) {
    .editor-fields {
        grid-template-columns: 1fr;
    }

    .editor-dialog {
        padding: 20px;
    }
}

/* AGENCY CLASSIFICATION */

.class-select,
.class-tag {
    display: inline-block;
    padding: 6px 12px;
    border-radius: 5px;
    border: none;
    font-size: 12px;
    font-weight: 600;
    min-width: 45px;
    text-align: center;
}

.grade-aplus {
    background: #a7d8bd;
    color: #245f40;
}

.grade-a {
    background: #c3e5ca;
    color: #326b40;
}

.grade-bplus {
    background: #d5e3f9;
    color: #37598c;
}

.grade-b {
    background: #f5e3b4;
    color: #86661f;
}

.grade-cplus {
    background: #f1d4b9;
    color: #975b2e;
}

.grade-c {
    background: #efc4c4;
    color: #963e3e;
}

.grade-none {
    background: var(--bg);
    color: var(--muted);
}

.class-select {
    cursor: pointer;
}

td {
    vertical-align: middle;
}

/* AGENCY MANAGEMENT */

[hidden] {
    display: none !important;
}

.agency-edit-button {
    padding: 6px 12px;
    font-size: 12px;
    border: 1px solid var(--border);
    border-radius: 5px;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
}

.editor-field input,
.editor-field select {
    width: 100%;
    padding: 12px;
    font: inherit;
    box-sizing: border-box;
    border: 1px solid var(--border);
    border-radius: 5px;
    background: var(--surface);
    color: var(--text);
}

.danger-button {
    color: #d45c5c;
    border: 1px solid #d45c5c;
    background: transparent;
    border-radius: 5px;
    padding: 10px 15px;
    cursor: pointer;
}

.archived-label {
    color: var(--muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.editor-actions button:disabled {
    opacity: .5;
    cursor: wait;
}

/* PARTNER CONTACTS */

.contact-card {
    padding: 18px;
    margin-top: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
}

.contact-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.contact-position {
    font-size: 12px;
    color: var(--muted);
    margin: 6px 0 15px;
}

.contact-value {
    font-size: 13px;
    margin: 8px 0;
    overflow-wrap: anywhere;
}

.contact-notes {
    padding: 12px;
    margin-top: 15px;
    background: var(--bg);
    border-radius: 5px;
    white-space: pre-wrap;
    font-size: 13px;
}

.contact-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 15px;
}

/* PARTNER CONTACTS EDITOR */

.partner-button {
    margin-left: 8px;
    cursor: pointer;
}

#contacts-dialog,
#contact-editor {
    width: min(720px, 92vw);
    max-height: 85vh;
    overflow-y: auto;
}

#contacts-dialog .contact-header {
    margin-top: 20px;
}

#contacts-dialog .contact-card .contact-header {
    margin-top: 0;
}

#contact-editor textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid #dddddd;
    border-radius: 5px;
    font: inherit;
    resize: vertical;
}

#contacts-dialog button,
#contact-editor button {
    cursor: pointer;
}
