/* ============================================================
   Documentation Portal — Global Styles
   Adapted from Melon Toolbox theme.
   Environment-aware accent: green (prod) / orange (UAT).
   ============================================================ */

/* ── Environment Palette ──────────────────────────────────── */
body[data-env="prod"] {
    --accent:             #16a34a;
    --accent-dark:        #14532d;
    --accent-light:       #86efac;
    --accent-bg:          #dcfce7;
    --accent-bg-subtle:   #f0fdf4;
    --accent-hover-shadow: rgba(22,163,74,.15);
    --accent-focus-ring:  rgba(22,163,74,.12);
}

body[data-env="uat"] {
    --accent:             #FF6B35;
    --accent-dark:        #c2410c;
    --accent-light:       #fdba74;
    --accent-bg:          #ffedd5;
    --accent-bg-subtle:   #fff7ed;
    --accent-hover-shadow: rgba(255,107,53,.15);
    --accent-focus-ring:  rgba(255,107,53,.12);
}

body:not([data-env]) {
    --accent:             #16a34a;
    --accent-dark:        #14532d;
    --accent-light:       #86efac;
    --accent-bg:          #dcfce7;
    --accent-bg-subtle:   #f0fdf4;
    --accent-hover-shadow: rgba(22,163,74,.15);
    --accent-focus-ring:  rgba(22,163,74,.12);
}

/* ── Base ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    padding-bottom: 60px;
    background: var(--accent-bg-subtle);
}

/* ── Header ───────────────────────────────────────────────── */
.tb-header {
    background: #ffffff;
    border-top: 4px solid var(--accent);
    border-bottom: 1px solid #e5e7eb;
    box-shadow: 0 1px 4px rgba(0,0,0,.06);
    position: sticky;
    top: 0;
    z-index: 50;
}

.tb-header-inner {
    max-width: 1280px;
    margin: 0 auto;
    padding: 12px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.tb-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
}

.tb-logo { height: 36px; width: auto; }

.tb-wordmark {
    font-size: 18px;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: -0.3px;
}

.tb-env-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: #ffffff;
    background: var(--accent);
    margin-left: 4px;
    vertical-align: middle;
}

.tb-header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.tb-agent {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.tb-role-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.tb-agent-email {
    font-size: 13px;
    color: #6b7280;
}

.tb-manage-link {
    font-size: 13px;
    font-weight: 600;
    color: var(--accent);
    text-decoration: none;
    padding: 4px 12px;
    border: 1px solid var(--accent-light);
    border-radius: 6px;
    transition: background .15s, color .15s;
}
.tb-manage-link:hover {
    background: var(--accent);
    color: #ffffff;
    border-color: var(--accent);
}

.tb-logout {
    font-size: 13px;
    font-weight: 600;
    color: #dc2626;
    text-decoration: none;
    padding: 4px 12px;
    border: 1px solid #fca5a5;
    border-radius: 6px;
    transition: background .15s, color .15s;
}
.tb-logout:hover {
    background: #dc2626;
    color: #ffffff;
    border-color: #dc2626;
}

.tb-subnav {
    max-width: 1280px;
    margin: 0 auto;
    padding: 6px 24px;
    display: flex;
    align-items: center;
    gap: 8px;
    border-top: 1px solid var(--accent-bg-subtle);
    background: #f9fafb;
    font-size: 13px;
}

.tb-subnav-link {
    color: var(--accent);
    text-decoration: none;
    font-weight: 500;
}
.tb-subnav-link:hover { text-decoration: underline; }
.tb-subnav-link.active { color: #6b7280; pointer-events: none; }
.tb-subnav-sep { color: #d1d5db; }
.tb-subnav-current { color: #374151; font-weight: 600; }

/* ── Footer ───────────────────────────────────────────────── */
.tb-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #ffffff;
    border-top: 1px solid #e5e7eb;
    padding: 10px 24px;
    z-index: 40;
}

.tb-footer-inner {
    max-width: 1280px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: #9ca3af;
}

.tb-footer-link { color: var(--accent); text-decoration: none; }
.tb-footer-link:hover { text-decoration: underline; }
.tb-footer-sep { color: #d1d5db; }
.tb-footer-version { font-weight: 600; color: #d1d5db; }

/* ── Page wrapper ─────────────────────────────────────────── */
.tb-page {
    max-width: 1280px;
    margin: 0 auto;
    padding: 32px 24px;
}

.tb-page-narrow {
    max-width: 600px;
    margin: 0 auto;
    padding: 48px 24px;
}

/* ── Alerts ───────────────────────────────────────────────── */
.alert {
    padding: 14px 18px;
    border-radius: 6px;
    font-weight: 700;
    font-size: 14px;
    margin-bottom: 20px;
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.alert-error   { background: #dc2626; color: #fff; border-left: 5px solid #991b1b; }
.alert-warning { background: #d97706; color: #fff; border-left: 5px solid #92400e; }
.alert-success { background: #16a34a; color: #fff; border-left: 5px solid #14532d; }
.alert-info    { background: #2563eb; color: #fff; border-left: 5px solid #1e40af; }
.alert-icon    { font-size: 16px; flex-shrink: 0; margin-top: 1px; }

/* ── Card ─────────────────────────────────────────────────── */
.tb-card {
    background: #ffffff;
    border-radius: 10px;
    border: 1px solid #e5e7eb;
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
    padding: 24px;
}

/* ── Section cards on dashboard ───────────────────────────── */
.section-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}

.section-card {
    display: flex;
    align-items: center;
    gap: 20px;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 14px;
    padding: 28px;
    text-decoration: none;
    color: #111827;
    transition: box-shadow .15s, transform .15s, border-color .15s;
    cursor: pointer;
}

.section-card:hover {
    box-shadow: 0 4px 14px var(--accent-hover-shadow);
    border-color: var(--accent-light);
    transform: translateY(-2px);
}

.section-card-icon {
    width: 56px;
    height: 56px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    flex-shrink: 0;
    background: var(--accent-bg);
}

.section-card-body { flex: 1; min-width: 0; }

.section-card-name {
    font-size: 18px;
    font-weight: 700;
}

.section-card-desc {
    font-size: 13px;
    color: #6b7280;
    margin-top: 4px;
}

.section-card-count {
    font-size: 12px;
    color: #9ca3af;
    margin-top: 6px;
}

.section-card-arrow {
    color: #d1d5db;
    font-size: 20px;
    flex-shrink: 0;
    transition: color .15s, transform .15s;
}
.section-card:hover .section-card-arrow {
    color: var(--accent);
    transform: translateX(3px);
}

/* ── Doc cards (in section view) ──────────────────────────── */
.doc-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

.doc-card {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 20px;
    text-decoration: none;
    color: #111827;
    transition: box-shadow .15s, transform .15s, border-color .15s;
    cursor: pointer;
    display: flex;
    flex-direction: column;
}

.doc-card:hover {
    box-shadow: 0 4px 14px var(--accent-hover-shadow);
    border-color: var(--accent-light);
    transform: translateY(-2px);
}

.doc-card-title {
    font-size: 15px;
    font-weight: 700;
    margin-bottom: 8px;
}

.doc-card-meta {
    font-size: 12px;
    color: #9ca3af;
    margin-top: auto;
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

/* ── Tool cards (reuse from toolbox) ──────────────────────── */
.tool-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 14px;
}

.tool-card {
    display: flex;
    align-items: center;
    gap: 14px;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 16px 18px;
    text-decoration: none;
    color: #111827;
    transition: box-shadow .15s, transform .15s, border-color .15s;
    cursor: pointer;
}
.tool-card:hover {
    box-shadow: 0 4px 14px var(--accent-hover-shadow);
    border-color: var(--accent-light);
    transform: translateY(-2px);
}

/* ── Form elements ────────────────────────────────────────── */
.form-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #374151;
    margin-bottom: 6px;
}

.form-input, .form-select {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid #d1d5db;
    border-radius: 7px;
    font-size: 14px;
    color: #111827;
    background: #ffffff;
    transition: border-color .15s, box-shadow .15s;
    outline: none;
}

.form-input:focus, .form-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-focus-ring);
}

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 20px;
    border-radius: 7px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: opacity .15s, transform .1s;
    text-decoration: none;
}
.btn:active { transform: scale(.98); }

.btn-primary   { background: var(--accent); color: #ffffff; }
.btn-primary:hover { opacity: .9; }

.btn-danger    { background: #dc2626; color: #ffffff; }
.btn-danger:hover { opacity: .9; }

.btn-secondary { background: #f3f4f6; color: #374151; border: 1px solid #e5e7eb; }
.btn-secondary:hover { background: #e5e7eb; }

.btn-sm { padding: 5px 12px; font-size: 12px; border-radius: 5px; }

.btn-outline-danger {
    background: transparent;
    color: #dc2626;
    border: 1px solid #fca5a5;
    border-radius: 5px;
    padding: 5px 10px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s, color .15s;
}
.btn-outline-danger:hover { background: #dc2626; color: #fff; border-color: #dc2626; }

/* ── Login card ───────────────────────────────────────────── */
.login-card {
    background: #ffffff;
    border-radius: 14px;
    box-shadow: 0 4px 24px rgba(0,0,0,.08);
    padding: 40px;
    border-top: 4px solid var(--accent);
}

.login-logo {
    display: block;
    max-width: 180px;
    margin: 0 auto 24px;
}

.login-title {
    text-align: center;
    font-size: 22px;
    font-weight: 700;
    color: #111827;
    margin-bottom: 6px;
}

.login-subtitle {
    text-align: center;
    font-size: 14px;
    color: #6b7280;
    margin-bottom: 28px;
}

/* ── Modal ────────────────────────────────────────────────── */
.tb-modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 100;
    align-items: center;
    justify-content: center;
}
.tb-modal-overlay.open { display: flex; }

.tb-modal {
    background: #ffffff;
    border-radius: 12px;
    padding: 28px;
    width: 100%;
    max-width: 480px;
    box-shadow: 0 8px 32px rgba(0,0,0,.18);
}

.tb-modal-title {
    font-size: 17px;
    font-weight: 700;
    color: #111827;
    margin-bottom: 20px;
}

/* ── Rich text block ──────────────────────────────────────── */
.block-container {
    margin-bottom: 20px;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    background: #ffffff;
    overflow: hidden;
}

.block-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px;
    background: #f9fafb;
    border-bottom: 1px solid #e5e7eb;
    font-size: 12px;
    color: #6b7280;
}

.block-actions {
    display: flex;
    gap: 6px;
}

.block-content {
    padding: 16px;
    font-size: 14px;
    line-height: 1.7;
    color: #374151;
}

.block-content img { max-width: 100%; height: auto; border-radius: 6px; }
.block-content h1, .block-content h2, .block-content h3 { margin: 12px 0 8px; color: #111827; }
.block-content p { margin: 8px 0; }
.block-content ul, .block-content ol { padding-left: 24px; margin: 8px 0; }
.block-content code { background: #f3f4f6; padding: 2px 6px; border-radius: 4px; font-size: 13px; }
.block-content pre { background: #1f2937; color: #f3f4f6; padding: 16px; border-radius: 8px; overflow-x: auto; }
.block-content pre code { background: transparent; padding: 0; color: inherit; }
.block-content blockquote { border-left: 4px solid var(--accent); padding-left: 16px; color: #6b7280; margin: 12px 0; }
.block-content a { color: var(--accent); text-decoration: underline; }
.block-content a.attachment-link,
.block-content a[href*="file_serve.php"] {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    color: var(--accent);
    font-weight: 600;
    font-size: 13px;
    text-decoration: none;
    transition: background .15s, border-color .15s;
}
.block-content a.attachment-link:hover,
.block-content a[href*="file_serve.php"]:hover {
    background: var(--accent-bg);
    border-color: var(--accent-light);
}

/* Quill editor overrides */
.ql-toolbar { border-radius: 8px 8px 0 0 !important; border-color: #e5e7eb !important; }
.ql-container { border-radius: 0 0 8px 8px !important; border-color: #e5e7eb !important; min-height: 200px; font-family: inherit !important; font-size: 14px !important; }
.ql-editor { min-height: 200px; }

/* ── File list ────────────────────────────────────────────── */
.file-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.file-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 14px;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    font-size: 13px;
}

.file-item-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #374151;
}

.file-item-size {
    color: #9ca3af;
    font-size: 12px;
    flex-shrink: 0;
}

.file-item-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

/* ── User management table ────────────────────────────────── */
.user-table {
    width: 100%;
    border-collapse: collapse;
}

.user-table th {
    text-align: left;
    padding: 10px 14px;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: #6b7280;
    border-bottom: 2px solid #e5e7eb;
}

.user-table td {
    padding: 10px 14px;
    font-size: 14px;
    border-bottom: 1px solid #f3f4f6;
}

.user-table tr:hover td {
    background: var(--accent-bg-subtle);
}

/* ── Utility classes ──────────────────────────────────────── */
.text-accent { color: var(--accent) !important; }
.bg-accent { background: var(--accent) !important; }
.bg-accent-bg { background: var(--accent-bg) !important; }

.empty-state {
    text-align: center;
    padding: 60px 24px;
    color: #9ca3af;
}

.empty-state-icon { font-size: 48px; margin-bottom: 16px; }
.empty-state-title { font-size: 18px; font-weight: 700; color: #6b7280; margin-bottom: 6px; }
.empty-state-text { font-size: 14px; }

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 640px) {
    .tb-header-inner { padding: 10px 16px; }
    .tb-wordmark     { display: none; }
    .tb-env-badge    { display: none; }
    .tb-agent-email  { display: none; }
    .tb-page         { padding: 20px 16px; }
    .section-grid    { grid-template-columns: 1fr; }
    .doc-grid        { grid-template-columns: 1fr; }
    .tool-grid       { grid-template-columns: 1fr; }
}

/* ── Scrollbar ────────────────────────────────────────────── */
::-webkit-scrollbar        { width: 6px; }
::-webkit-scrollbar-track  { background: transparent; }
::-webkit-scrollbar-thumb  { background: #d1d5db; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #9ca3af; }
