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

body {
    font-family: "Manrope", "Segoe UI", sans-serif;
    font-size: 14px;
    background: linear-gradient(180deg, #f8fbf8 0%, #f4f7f4 50%, #eef3ef 100%);
    color: #0f1c13;
    line-height: 1.5;
}

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

a {
    color: inherit;
    text-decoration: none;
}

.app-header {
    background: linear-gradient(120deg, #0f3d2e, #115b3e);
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    padding: 14px 20px;
    backdrop-filter: blur(6px);
    position: sticky;
    top: 0;
    z-index: 10;
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.28);
    position: relative;
}

.app-title {
    display: flex;
    align-items: center;
    gap: 10px;
}

.app-title h1 {
    font-size: 18px;
    font-weight: 800;
    letter-spacing: 0.2px;
    color: #f4fff8;
}

.badge {
    font-size: 11px;
    border-radius: 999px;
    padding: 4px 10px;
    background: rgba(255, 255, 255, 0.16);
    border: 1px solid rgba(255, 255, 255, 0.25);
    color: #0f3d2e;
}

.app-subtitle {
    font-size: 12px;
    color: #d2e6d9;
    margin-top: 4px;
}

.header-actions {
    position: absolute;
    right: 20px;
    top: 14px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.greeting {
    font-weight: 700;
    color: #f4fff8;
}

.app-logo {
    width: 42px;
    height: 42px;
    border-radius: 10px;
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.18);
}

.sap-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 210px;
    gap: 14px;
    padding: 14px 18px 24px;
    align-items: start;
}

.sap-center {
    min-height: 70vh;
}

.card {
    background: #ffffff;
    border: 1px solid rgba(0, 0, 0, 0.05);
    border-radius: 12px;
    box-shadow: 0 18px 30px rgba(0, 0, 0, 0.12);
    overflow: hidden;
}

.panel {
    padding: 14px;
}

.card h2 {
    font-size: 15px;
    font-weight: 800;
    color: #0f3d2e;
    margin-bottom: 8px;
}

.card.placeholder {
    padding: 20px;
}

.muted {
    color: #61756a;
}

.small {
    font-size: 12px;
}

.alert {
    border: 1px solid rgba(15, 61, 46, 0.16);
    background: rgba(39, 174, 96, 0.12);
    color: #0f3d2e;
    padding: 10px 12px;
    border-radius: 10px;
    margin-bottom: 8px;
}

.alert-error {
    background: rgba(220, 53, 69, 0.1);
    border-color: rgba(220, 53, 69, 0.2);
    color: #a3182f;
}

.alert-ok {
    background: rgba(39, 174, 96, 0.12);
    border-color: rgba(39, 174, 96, 0.25);
    color: #0f3d2e;
}

/* Sociedades */

.company-list {
    list-style: none;
    padding: 0;
    margin: 6px 0 12px;
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-radius: 10px;
    background: #ffffff;
    max-height: 190px;
    overflow: auto;
}

.company-list li a {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 10px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.04);
    font-size: 13px;
    color: #0f1c13;
}

.company-list li:last-child a {
    border-bottom: none;
}

.company-list li.active a,
.company-list li a:hover {
    background: linear-gradient(90deg, rgba(46, 204, 113, 0.14), rgba(46, 204, 113, 0.08));
}

.tag {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 6px;
    background: rgba(46, 204, 113, 0.14);
    border: 1px solid rgba(46, 204, 113, 0.28);
    color: #0f3d2e;
}

/* Formularios */

.form-vertical {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 4px;
}

.form-vertical label {
    font-size: 12px;
    font-weight: 700;
    color: #0f3d2e;
}

input[type="text"],
input[type="number"],
textarea {
    width: 100%;
    padding: 8px 10px;
    border-radius: 10px;
    border: 1px solid rgba(0, 0, 0, 0.08);
    background: #f9fbf9;
    color: #0f1c13;
    font-size: 13px;
    transition: border 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

input[type="text"]:focus,
input[type="number"]:focus,
textarea:focus {
    outline: none;
    border-color: rgba(46, 204, 113, 0.7);
    box-shadow: 0 0 0 3px rgba(46, 204, 113, 0.18);
    background: #ffffff;
}

button {
    border: none;
    cursor: pointer;
}

.btn-block {
    width: 100%;
    margin-top: 8px;
    padding: 10px 12px;
    border-radius: 12px;
    background: linear-gradient(120deg, #2ecc71, #1faa5a);
    color: #ffffff;
    font-weight: 800;
    font-size: 13px;
    border: 1px solid rgba(0, 0, 0, 0.06);
    box-shadow: 0 8px 20px rgba(46, 204, 113, 0.3);
    transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.btn-block:hover {
    transform: translateY(-1px);
    box-shadow: 0 10px 24px rgba(46, 204, 113, 0.4);
}

.btn-block.primary {
    background: linear-gradient(120deg, #34d399, #16a34a);
}

.btn-small {
    padding: 8px 12px;
    border-radius: 999px;
    background: #f4fbf6;
    color: #0f3d2e;
    font-size: 12px;
    border: 1px solid rgba(0, 0, 0, 0.06);
    transition: transform 0.1s ease, box-shadow 0.1s ease, background 0.1s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-small.primary {
    background: linear-gradient(120deg, #2ecc71, #1faa5a);
    color: #ffffff;
    box-shadow: 0 8px 18px rgba(46, 204, 113, 0.28);
}

.btn-small:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.14);
}

.btn-small.primary::before {
    content: "✔";
    font-size: 12px;
}

.open-create::before,
.open-create-root::before {
    content: "+";
    font-weight: 800;
}

.btn-small:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

.inline-form {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.chk-inline {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: #0f3d2e;
}

input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: #22c55e;
}

.radio-inline {
    display: flex;
    gap: 12px;
    align-items: center;
    font-size: 12px;
    color: #0f3d2e;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 8px 12px;
    margin: 6px 0;
}

.form-grid label {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.form-grid select {
    padding: 8px 10px;
    border-radius: 10px;
    border: 1px solid rgba(0, 0, 0, 0.08);
    background: #f9fbf9;
    font-size: 13px;
    color: #0f1c13;
}

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

.toolbar h3 {
    font-size: 14px;
    color: #0f3d2e;
    letter-spacing: 0.15px;
}

.company-drawer-bar {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.company-lock-label {
    font-weight: 700;
    color: #0f3d2e;
}

.company-selector select {
    padding: 8px 10px;
    border-radius: 10px;
    border: 1px solid rgba(0, 0, 0, 0.08);
    background: #f9fbf9;
    color: #0f1c13;
}

.drawer-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.drawer-chip {
    padding: 8px 12px;
    border-radius: 999px;
    border: 1px solid rgba(0, 0, 0, 0.06);
    background: #f4fbf6;
    color: #0f3d2e;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    text-decoration: none;
}

.drawer-chip.active {
    background: linear-gradient(120deg, rgba(46, 204, 113, 0.18), rgba(46, 204, 113, 0.1));
    border-color: rgba(46, 204, 113, 0.6);
    color: #0f1c13;
}

.icon-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
}

.card-body {
    padding: 12px 14px;
}

.card-header,
.card-footer {
    padding: 12px 14px;
}

.card-footer {
    border-top: 1px solid rgba(0, 0, 0, 0.05);
    background: #f8fbf8;
}

/* Árbol de cuentas compacto */

.account-tree {
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-radius: 12px;
    background: #ffffff;
    max-height: 520px;
    overflow: auto;
    padding: 8px 10px;
}

.account-level {
    list-style: none;
    padding-left: 14px;
    margin: 2px 0;
}

.account-item {
    position: relative;
}

.account-item.is-collapsed > ul {
    display: none;
}

.tree-toggle {
    width: 24px;
    height: 24px;
    border-radius: 8px;
    border: 1px solid rgba(0, 0, 0, 0.06);
    background: #f4fbf6;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: #0f3d2e;
    transition: transform 0.12s ease, background 0.12s ease, box-shadow 0.12s ease;
}

.tree-toggle::before {
    content: "▾";
}

.account-item.is-collapsed > .account-node .tree-toggle::before {
    content: "▸";
}

.tree-toggle:hover {
    transform: translateX(1px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.12);
    background: #e8f7ed;
}

.tree-toggle-empty {
    visibility: hidden;
}

.account-node {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 6px;
    border-radius: 10px;
    transition: background 0.12s ease, transform 0.12s ease;
    position: relative;
}

.account-node::before {
    content: "🗂️";
    font-size: 14px;
    opacity: 0.8;
}

.account-node:hover {
    background: rgba(46, 204, 113, 0.08);
    transform: translateX(2px);
}

.account-code {
    font-family: "JetBrains Mono", "SFMono-Regular", monospace;
    font-size: 12px;
    color: #0f3d2e;
    min-width: 60px;
}

.account-name {
    font-size: 13px;
    color: #0f1c13;
    flex: 1;
}

.account-title {
    font-weight: 800;
    color: #15803d;
}

.account-node .icon-btn {
    opacity: 0.7;
}

.account-node .icon-btn:hover {
    opacity: 1;
}

/* Rail de cajones */

.drawer-rail {
    background: #ffffff;
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-radius: 12px;
    padding: 10px;
    box-shadow: inset 0 1px 0 rgba(0, 0, 0, 0.04), 0 12px 24px rgba(0, 0, 0, 0.08);
    position: sticky;
    top: 70px;
    max-height: calc(100vh - 90px);
    overflow: auto;
}

.rail-header {
    font-size: 13px;
    font-weight: 700;
    color: #0f3d2e;
    margin-bottom: 8px;
    text-align: center;
}

.rail-placeholder {
    font-size: 12px;
    color: #61756a;
    text-align: center;
    padding: 12px 8px;
    border: 1px dashed rgba(0, 0, 0, 0.12);
    border-radius: 10px;
    background: #f8fbf8;
}

.drawer-tile {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    margin-bottom: 8px;
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-radius: 12px;
    background: #f9fbf9;
    color: #0f1c13;
    text-decoration: none;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.08);
    transition: transform 0.12s ease, box-shadow 0.12s ease, border 0.12s ease;
    position: relative;
    overflow: hidden;
}

.drawer-tile::before {
    content: "🗄️";
    margin-right: 8px;
}

.drawer-tile:hover {
    transform: translateY(-1px);
    border-color: rgba(46, 204, 113, 0.5);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.12);
}

.drawer-tile.active {
    background: linear-gradient(120deg, rgba(46, 204, 113, 0.18), rgba(46, 204, 113, 0.08));
    border-color: rgba(46, 204, 113, 0.8);
}

.drawer-label {
    font-size: 13px;
    font-weight: 700;
}

.drawer-code {
    font-size: 12px;
    font-weight: 700;
    color: #15803d;
}

/* Modal */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 64, 32, 0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
    backdrop-filter: blur(4px);
}

.modal {
    background: #ffffff;
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-radius: 14px;
    width: 540px;
    max-width: 92vw;
    box-shadow: 0 14px 30px rgba(0, 0, 0, 0.18);
}

.modal.wide {
    width: 720px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 14px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    background: linear-gradient(120deg, rgba(46, 204, 113, 0.12), rgba(21, 93, 62, 0.1));
    border-radius: 14px 14px 0 0;
}

.modal-header h3 {
    font-size: 14px;
    color: #0f3d2e;
}

.modal-close {
    background: #f8fbf8;
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 50%;
    width: 28px;
    height: 28px;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    color: #0f1c13;
}

.modal-body {
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.modal-body label {
    font-size: 12px;
    font-weight: 700;
    color: #0f3d2e;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.modal-body textarea {
    resize: vertical;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 6px;
}

.company-list.compact {
    max-height: none;
    border: none;
    background: transparent;
}

.company-list.compact li {
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    padding: 6px 0;
}

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

/* Responsivo */
@media (max-width: 1100px) {
    .sap-layout {
        grid-template-columns: 1fr;
    }
    .drawer-rail {
        position: relative;
        max-height: none;
    }
}
