@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap');

/* ---- Variables ---- */
:root {
    --color-primary: #2d3f86;
    --color-primary-dark: #232f6a;
    --color-accent: #e85036;
    --color-accent-dark: #d0442c;
    --color-text: #5e5e5e;
    --color-text-strong: #1a1a1a;
    --color-text-muted: #6b7280;
    --color-bg: #f6f6f6;
    --color-surface: #fff;
    --color-border: #d1d5db;
    --color-border-light: #e5e7eb;
    --color-error: #991b1b;
    --color-error-bg: #fef2f2;
    --color-error-border: #fecaca;
    --color-success: #166534;
    --color-success-bg: #f0fdf4;
    --color-success-border: #bbf7d0;
    --radius: 4px;
    --radius-lg: 8px;
}

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

/* ---- Base ---- */
body {
    font-family: "Poppins", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    line-height: 1.6;
    color: var(--color-text);
    background: var(--color-surface);
    padding: 2rem 1rem;
}

a {
    color: var(--color-primary);
}

h1, h2, h3 {
    color: var(--color-text-strong);
}

h1 {
    font-size: 1.75rem;
    margin-bottom: 0.5rem;
}

h2 {
    font-size: 1.25rem;
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
}

p {
    margin-bottom: 0.75rem;
}

ul, ol {
    margin-bottom: 0.75rem;
    padding-left: 1.5rem;
}

/* ---- Layout ---- */
.container {
    max-width: 700px;
    margin: 0 auto;
    padding: 2rem;
}

.container-wide {
    max-width: 100%;
}

.text-center {
    text-align: center;
}

/* ---- Brand ---- */
.brand-logo {
    display: block;
    max-width: 200px;
    margin: 0 auto 1.5rem;
}

/* ---- Sections ---- */
.section-list {
    margin-bottom: 2rem;
}

.section-item {
    margin-bottom: 1.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--color-border-light);
}

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

.section-item p {
    margin-bottom: 0.5rem;
}

.section-item img {
    width: 100%;
    height: auto;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    margin-top: 0.5rem;
}

/* ---- Form ---- */
.form-group {
    margin-bottom: 1rem;
}

label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.25rem;
    font-size: 0.9rem;
    color: var(--color-text-strong);
}

.hint {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    margin-bottom: 0.5rem;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"],
textarea,
select {
    display: block;
    width: 100%;
    padding: 0.5rem 0.75rem;
    font-size: 0.95rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-family: inherit;
    height: 2.6rem;
}

textarea {
    height: auto;
    resize: vertical;
}

select {
    appearance: none;
    -webkit-appearance: none;
    background: white url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23666' stroke-width='1.5' fill='none'/%3E%3C/svg%3E") no-repeat right 0.75rem center;
    padding-right: 2rem;
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
input[type="date"]:focus,
select:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(45, 63, 134, 0.2);
}

.form-help {
    font-size: 0.85rem;
    color: #666;
    margin: 0.25rem 0 1rem;
}

.filter-form {
    display: grid;
    grid-template-columns: repeat(2, minmax(10rem, 12rem)) minmax(14rem, 1fr) auto;
    gap: 0.75rem;
    align-items: end;
    margin: 1rem 0;
    padding: 1rem;
    background: var(--color-bg);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-lg);
}

.filter-form label {
    margin-bottom: 0;
}

.filter-form input,
.filter-form select {
    margin-bottom: 0;
}

.filter-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-height: 2.6rem;
}

.filter-actions .btn-primary {
    height: 2.6rem;
    padding: 0.5rem 1rem;
}

.document-filter-summary {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.document-filter-summary a {
    margin-left: 0.5rem;
}

.input-with-toggle {
    position: relative;
    margin-bottom: 1rem;
}

.input-with-toggle input {
    margin-bottom: 0;
    padding-right: 5rem;
}

.btn-toggle {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--color-primary);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    padding: 0.25rem 0.5rem;
}

.btn-toggle:hover {
    color: var(--color-primary-dark);
}

.btn-primary {
    background: var(--color-accent);
    color: #fff;
    border: none;
    padding: 0.6rem 1.5rem;
    font-size: 0.95rem;
    font-weight: 600;
    border-radius: var(--radius);
    cursor: pointer;
    font-family: inherit;
    text-decoration: none;
    display: inline-block;
    white-space: nowrap;
}

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

.btn-primary:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

.btn-signed {
    background: #27ae60;
    color: #fff;
    border: none;
    padding: 0.6rem 1.5rem;
    font-size: 0.95rem;
    font-weight: 600;
    border-radius: var(--radius);
    cursor: default;
    font-family: inherit;
}

.btn-link {
    background: none;
    border: none;
    color: var(--color-primary);
    cursor: pointer;
    font-size: inherit;
    padding: 0;
    text-decoration: none;
}

.btn-link:hover {
    color: var(--color-accent-dark);
    text-decoration: underline;
}

.btn-danger {
    background: #c0392b;
    color: #fff;
    border: none;
    padding: 0.6rem 1.5rem;
    font-size: 0.95rem;
    font-weight: 600;
    border-radius: var(--radius);
    cursor: pointer;
    font-family: inherit;
    display: inline-block;
}

.btn-danger:hover {
    background: #96281b;
}

.form-actions {
    align-items: center;
    display: flex;
    gap: 1rem;
    margin-top: 1rem;
}

.checkbox-group {
    margin-bottom: 1.25rem;
}

.checkbox-label {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    font-weight: 400;
    font-size: 0.9rem;
    color: var(--color-text);
    cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
    flex-shrink: 0;
}

/* ---- Dividers ---- */
.divider {
    border: none;
    border-top: 2px solid var(--color-border-light);
    margin: 2rem 0 1.5rem;
}

/* ---- Alerts ---- */
.alert {
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1rem;
}

.alert p:last-child {
    margin-bottom: 0;
}

.alert-error {
    background: var(--color-error-bg);
    border: 1px solid var(--color-error-border);
    color: var(--color-error);
}

.alert-success {
    background: var(--color-success-bg);
    border: 1px solid var(--color-success-border);
    color: var(--color-success);
}

.alert-warning {
    background: #fffbeb;
    border: 1px solid #fde68a;
    color: #92400e;
}

.input-error {
    border-color: var(--color-error);
    box-shadow: 0 0 0 1px var(--color-error);
}

.back-link {
    margin-top: 1rem;
}

/* ---- Tip boxes ---- */
.tip {
    background: #fef2ee;
    border-left: 3px solid var(--color-accent);
    padding: 0.65rem 0.85rem;
    margin-bottom: 0.75rem;
    font-size: 0.88rem;
    border-radius: 0 var(--radius) var(--radius) 0;
}

.tip p {
    margin-bottom: 0;
}

/* ---- Secondary headings ---- */
.section-heading-secondary {
    color: var(--color-accent);
}

/* ---- Footer ---- */
.page-footer {
    max-width: 700px;
    margin: 1.5rem auto 0;
    padding: 0 2rem;
    font-size: 0.85rem;
    color: var(--color-text-muted);
}

.page-footer a {
    color: var(--color-text-muted);
    text-decoration: none;
}

.page-footer a:hover {
    color: var(--color-primary);
    text-decoration: underline;
}

.page-footer-copyright {
    margin-top: 0.35rem;
    font-size: 0.8rem;
}

/* ---- Data tables ---- */
.db-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1.5rem;
    font-size: 0.88rem;
}

.db-table th {
    background: var(--color-primary);
    color: #fff;
    text-align: left;
    padding: 0.5rem 0.75rem;
    font-weight: 600;
}

.db-table td {
    padding: 0.45rem 0.75rem;
    border-bottom: 1px solid var(--color-border-light);
    vertical-align: top;
}

.db-table tr:last-child td {
    border-bottom: 1px solid var(--color-border-light);
}

.detail-table td:first-child {
    width: 11rem;
    color: var(--color-text-strong);
    font-weight: 600;
    white-space: nowrap;
}

.detail-table code {
    overflow-wrap: anywhere;
}

.audit-table td:first-child {
    white-space: nowrap;
}

.workspace-hierarchy-table {
    table-layout: fixed;
}

.workspace-hierarchy-table .workspace-col-status {
    width: 9rem;
}

.workspace-hierarchy-table .workspace-col-initiator {
    width: 18rem;
}

.workspace-hierarchy-table .workspace-col-actions {
    width: 24rem;
}

.workspace-hierarchy-table .entity-actions {
    white-space: nowrap;
}

.db-table .prop-name {
    font-weight: 600;
    color: var(--color-text-strong);
    white-space: nowrap;
}

.db-table .prop-type {
    white-space: nowrap;
    color: var(--color-text-muted);
}

.db-table .sub-row td {
    padding-left: 2rem;
    font-size: 0.82rem;
    color: var(--color-text-muted);
    border-bottom: 1px solid var(--color-border-light);
}

.db-table .sub-row td:first-child::before {
    content: "\2514\00a0";
}

.db-row:hover {
    background: var(--color-bg);
}

.disclosure-arrow {
    display: inline-block;
    transition: transform 0.15s;
    margin-right: 0.4rem;
    font-size: 0.75rem;
}

.disclosure-arrow.open {
    transform: rotate(90deg);
}

.entity-actions {
    display: inline-flex;
    align-items: baseline;
    flex-wrap: wrap;
}

.entity-actions > * {
    display: inline-flex;
    align-items: baseline;
}

.entity-actions > * + * {
    position: relative;
    margin-left: 0.7em;
}

.entity-actions > * + *::before {
    content: "\00b7";
    color: var(--color-text-muted);
    position: absolute;
    left: -0.45em;
    text-decoration: none;
}

.inline-action {
    display: inline-flex;
}

.link-btn {
    background: none;
    border: none;
    padding: 0;
    color: var(--color-primary);
    cursor: pointer;
    font: inherit;
    text-decoration: none;
}

.link-btn:hover {
    text-decoration: underline;
}

.notion-link {
    text-decoration: none;
    font-size: 0.8em;
    opacity: 0.5;
}

.db-table td.hierarchy-cell-document,
.db-table td.empty-row-document {
    padding-left: 2rem;
}

.db-table td.hierarchy-cell-revision {
    padding-left: 4rem;
}

.empty-cell {
    text-align: center;
    color: var(--color-text-muted);
}

.empty-placeholder {
    color: var(--color-text-muted);
}

/* ---- Admin bar ---- */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 1rem;
}

.page-header h1 {
    margin-bottom: 0;
}

.page-header-actions {
    display: flex;
    gap: 1rem;
    align-items: center;
    font-size: 0.9rem;
}

.page-header-actions a,
.admin-user a,
.db-table a:not(.notion-link) {
    text-decoration: none;
}

.page-header-actions a:hover,
.admin-user a:hover,
.db-table a:not(.notion-link):hover {
    text-decoration: underline;
}

.admin-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.4rem 1rem;
    margin: -2rem -1rem 1.5rem;
    font-size: 0.85rem;
    color: var(--color-text-muted);
    border-bottom: 1px solid var(--color-border-light);
}

.admin-breadcrumbs a {
    color: var(--color-text-muted);
    text-decoration: none;
}

.admin-breadcrumbs a:hover {
    color: var(--color-primary);
    text-decoration: underline;
}

.admin-user {
    white-space: nowrap;
}

.admin-logout {
    background: none;
    border: none;
    color: var(--color-text-muted);
    font-size: 0.85rem;
    font-family: inherit;
    cursor: pointer;
    padding: 0;
    text-decoration: none;
}

.admin-logout:hover {
    color: var(--color-primary);
    text-decoration: underline;
}

/* ---- Status badges ---- */
.status-active {
    color: #16a34a;
    font-weight: 600;
}

.status-draft {
    color: #92400e;
    font-weight: 600;
}

.status-inactive {
    color: #dc2626;
    font-weight: 600;
}

.status-neutral {
    color: var(--color-text-muted);
    font-weight: 600;
}

/* ---- Setup verification log ---- */
.setup-log {
    background: var(--color-text-strong);
    color: var(--color-border);
    font-family: monospace;
    font-size: 0.82rem;
    line-height: 1.7;
    padding: 1rem 1.25rem;
    border-radius: var(--radius);
    margin-top: 1rem;
    max-height: 400px;
    overflow-y: auto;
}

.setup-log .log-success { color: #6ec96e; }
.setup-log .log-error { color: #e87272; }
.setup-log .log-warning {
    color: #f5c542;
    margin-top: 0.4rem;
    padding-top: 0.4rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.setup-banner { margin-top: 1rem; }
.setup-actions {
    margin-top: 0.75rem;
    margin-bottom: 1rem;
}

.clickable-row {
    cursor: pointer;
}

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

/* Signing page two-column layout */
.signing-layout {
    display: grid;
    grid-template-columns: 1fr 420px;
    gap: 1.5rem;
    padding: 0 1.5rem;
    min-height: calc(100vh - 3rem);
}

.signing-pdf {
    position: sticky;
    top: 3rem;
    height: calc(100vh - 3rem);
}

.signing-pdf-iframe {
    width: 100%;
    height: 100%;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
}

.signing-sidebar {
    display: flex;
    flex-direction: column;
    padding: 1rem 0;
    max-height: calc(100vh - 3rem);
}

.signing-sidebar-scroll {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.sidebar-label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--color-text-strong);
    margin: 1rem 0 0.25rem;
}

.signing-sidebar-scroll .sidebar-label:first-child {
    margin-top: 0;
}

.sidebar-links {
    list-style: none;
    padding: 0;
    margin: 0 0 0.5rem;
    font-size: 0.88rem;
}

.sidebar-links li {
    padding: 0.15rem 0;
}

.signing-meta {
    margin: 1rem 0 0;
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

.signers-section {
    margin-bottom: 0.5rem;
}

.signer-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 0.35rem 0;
    border-bottom: 1px solid var(--color-border-light);
    font-size: 0.85rem;
}

.signer-row:last-child {
    border-bottom: none;
}

.signer-name {
    color: var(--color-text);
}

.signer-status {
    white-space: nowrap;
    margin-left: 0.5rem;
}

.status-signed {
    color: #27ae60;
    font-weight: 600;
}

.status-date {
    color: var(--color-text-muted);
    font-size: 0.78rem;
    font-weight: 400;
}

.status-opened {
    color: var(--color-primary);
}

.status-pending {
    color: var(--color-text-muted);
}

.signing-form {
    flex-shrink: 0;
    padding-top: 1rem;
}

@media (max-width: 900px) {
    .filter-form {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .filter-actions {
        grid-column: 1 / -1;
    }

    .signing-layout {
        grid-template-columns: 1fr;
        min-height: auto;
    }

    .signing-pdf {
        position: static;
        height: 70vh;
    }
}

@media (max-width: 600px) {
    .filter-form {
        grid-template-columns: 1fr;
    }
}
