/* ============================================================
   CSS Custom Properties — Dark / Light themes
   ============================================================ */
:root,
[data-theme="dark"] {
    --bg-page:       #1a1d23;
    --bg-header:     #12151a;
    --bg-panel:      #21252b;
    --bg-panel-hd:   #2c313a;
    --bg-textarea:   #1e2229;
    --bg-pre:        #1e2229;
    --bg-btn-primary:   #4a9eff;
    --bg-btn-secondary: #5c6370;
    --bg-btn-success:   #4caf7d;
    --bg-btn-danger:    #e06c75;
    --bg-panel-btn:  #2c313a;
    --text-primary:  #abb2bf;
    --text-heading:  #e6e6e6;
    --text-muted:    #636d83;
    --text-btn:      #ffffff;
    --border-color:  #3d424d;
    --status-ok-bg:  #1e3a2a;
    --status-ok-txt: #4caf7d;
    --status-err-bg: #3a1e22;
    --status-err-txt:#e06c75;
    --brand-color:   #4a9eff;
    --scrollbar-thumb: #3d424d;
    --scrollbar-track: #1a1d23;
    --hljs-theme-url: "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/atom-one-dark.min.css";
}

[data-theme="light"] {
    --bg-page:       #f5f5f5;
    --bg-header:     #ffffff;
    --bg-panel:      #ffffff;
    --bg-panel-hd:   #f0f0f0;
    --bg-textarea:   #fafafa;
    --bg-pre:        #fafafa;
    --bg-btn-primary:   #2979ff;
    --bg-btn-secondary: #757575;
    --bg-btn-success:   #2e7d52;
    --bg-btn-danger:    #c62828;
    --bg-panel-btn:  #e8e8e8;
    --text-primary:  #383a42;
    --text-heading:  #181a1f;
    --text-muted:    #9a9a9a;
    --text-btn:      #ffffff;
    --border-color:  #d0d0d0;
    --status-ok-bg:  #e8f5e9;
    --status-ok-txt: #2e7d52;
    --status-err-bg: #ffebee;
    --status-err-txt:#c62828;
    --brand-color:   #2979ff;
    --scrollbar-thumb: #c0c0c0;
    --scrollbar-track: #f5f5f5;
}

/* ============================================================
   Reset & Base
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg-page);
    color: var(--text-primary);
    font-size: 14px;
    transition: background-color 0.2s, color 0.2s;
}

body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ============================================================
   Header
   ============================================================ */
.app-header {
    background-color: var(--bg-header);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    position: relative;
    z-index: 100;
}

.header-inner {
    max-width: 1600px;
    margin: 0 auto;
    padding: 0 16px;
    height: 52px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.app-brand {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--brand-color);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 8px;
    letter-spacing: -0.3px;
    flex-shrink: 0;
}

.app-brand:hover { opacity: 0.85; }

.brand-icon {
    font-size: 1.25rem;
    font-weight: 900;
    font-family: "Fira Code", "Consolas", monospace;
}

/* ---- Navigation ---- */
.app-nav { margin-left: 16px; flex: 1; }

.nav-list {
    list-style: none;
    display: flex;
    align-items: center;
    gap: 2px;
    margin: 0;
    padding: 0;
}

.nav-link {
    display: block;
    padding: 6px 12px;
    border-radius: 6px;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    background: none;
    border: none;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s, color 0.15s;
    line-height: 1.5;
}

.nav-link:hover,
.nav-link:focus {
    background: var(--bg-panel-hd);
    color: var(--text-heading);
    outline: none;
}

/* Active nav link (current page) */
.nav-link.active {
    color: var(--brand-color);
    background: var(--bg-panel-hd);
}

/* ---- Dropdown ---- */
.nav-dropdown { position: relative; }

.nav-dropdown-toggle { display: flex; align-items: center; gap: 4px; }

.nav-caret {
    font-size: 0.7rem;
    transition: transform 0.2s;
    display: inline-block;
}

.nav-dropdown.open .nav-caret { transform: rotate(180deg); }

.nav-dropdown-menu {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    min-width: 170px;
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 4px;
    list-style: none;
    box-shadow: 0 8px 24px rgba(0,0,0,0.25);
    z-index: 200;
}

.nav-dropdown.open .nav-dropdown-menu { display: block; }

.nav-dropdown-item {
    display: block;
    padding: 8px 12px;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 0.875rem;
    border-radius: 5px;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
}

.nav-dropdown-item:hover {
    background: var(--bg-panel-hd);
    color: var(--text-heading);
}

/* ---- Hamburger (mobile) ---- */
.nav-hamburger {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 36px;
    height: 36px;
    padding: 6px;
    background: var(--bg-panel-hd);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    margin-left: auto;
}

.nav-hamburger span {
    display: block;
    height: 2px;
    background: var(--text-primary);
    border-radius: 2px;
    transition: transform 0.2s, opacity 0.2s;
}

.nav-hamburger.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.nav-hamburger.open span:nth-child(2) { opacity: 0; }
.nav-hamburger.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* Theme toggle */
.theme-toggle-btn {
    background: var(--bg-panel-hd);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 6px 10px;
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    transition: background 0.2s, border-color 0.2s;
    color: var(--text-primary);
    flex-shrink: 0;
    margin-left: auto;
}

.theme-toggle-btn:hover {
    background: var(--bg-btn-secondary);
    color: var(--text-btn);
}

/* ---- Mobile nav ---- */
@media (max-width: 768px) {
    .nav-hamburger { display: flex; }

    .app-nav {
        display: none;
        position: absolute;
        top: 52px;
        left: 0;
        right: 0;
        background: var(--bg-header);
        border-bottom: 1px solid var(--border-color);
        padding: 8px 16px 12px;
        margin-left: 0;
    }

    .app-nav.open { display: block; }

    .nav-list { flex-direction: column; align-items: stretch; gap: 2px; }

    .nav-link { width: 100%; }

    .nav-dropdown-menu {
        position: static;
        box-shadow: none;
        border: none;
        background: var(--bg-panel-hd);
        border-radius: 6px;
        margin-top: 2px;
        padding: 2px;
    }

    .theme-toggle-btn { margin-left: 0; }
}

/* ============================================================
   Main / formatter layout
   ============================================================ */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.formatter-container {
    display: flex;
    flex-direction: column;
    flex: 1;
    max-width: 1600px;
    width: 100%;
    margin: 0 auto;
    padding: 12px 16px;
    gap: 10px;
    height: calc(100vh - 52px);
}

/* ============================================================
   Toolbar
   ============================================================ */
.formatter-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.toolbar-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.action-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    color: var(--text-btn);
    transition: opacity 0.15s, transform 0.1s;
    white-space: nowrap;
}

.action-btn:hover { opacity: 0.85; }
.action-btn:active { transform: scale(0.97); }

.action-btn.primary   { background-color: var(--bg-btn-primary); }
.action-btn.secondary { background-color: var(--bg-btn-secondary); }
.action-btn.success   { background-color: var(--bg-btn-success); }
.action-btn.danger    { background-color: var(--bg-btn-danger); }

/* ============================================================
   Status bar
   ============================================================ */
.status-bar {
    padding: 8px 14px;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    font-family: "Fira Code", "Consolas", monospace;
}

.status-bar.hidden { display: none; }
.status-bar.ok  { background: var(--status-ok-bg);  color: var(--status-ok-txt); }
.status-bar.err { background: var(--status-err-bg); color: var(--status-err-txt); }

/* ============================================================
   Two-panel layout
   ============================================================ */
.formatter-panels {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    flex: 1;
    min-height: 0;
}

.panel {
    display: flex;
    flex-direction: column;
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
    min-height: 0;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--bg-panel-hd);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.panel-title {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
}

.panel-btn {
    font-size: 0.78rem;
    padding: 4px 10px;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    background: var(--bg-panel-btn);
    color: var(--text-primary);
    cursor: pointer;
    transition: background 0.15s;
}

.panel-btn:hover { background: var(--bg-btn-secondary); color: var(--text-btn); }

/* ============================================================
   Input textarea
   ============================================================ */
.json-textarea {
    flex: 1;
    width: 100%;
    min-height: 0;
    padding: 14px;
    background: var(--bg-textarea);
    color: var(--text-primary);
    border: none;
    outline: none;
    resize: none;
    font-family: "Fira Code", "Cascadia Code", "Consolas", "Monaco", monospace;
    font-size: 1rem;
    line-height: 1.6;
    tab-size: 2;
    transition: background 0.2s, color 0.2s;
}

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

/* ============================================================
   Output <pre><code>
   ============================================================ */
.json-output-pre {
    flex: 1;
    margin: 0;
    overflow: auto;
    background: var(--bg-pre) !important;
    border-radius: 0;
}

.json-output-pre code {
    display: block;
    padding: 14px !important;
    font-family: "Fira Code", "Cascadia Code", "Consolas", "Monaco", monospace;
    font-size: 1rem;
    line-height: 1.6;
    background: transparent !important;
    white-space: pre;
    tab-size: 2;
}

/* ============================================================
   Scrollbars (WebKit)
   ============================================================ */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--scrollbar-track); }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--bg-btn-secondary); }

/* ============================================================
   Responsive — stack panels on small screens
   ============================================================ */
@media (max-width: 768px) {
    .formatter-container { height: auto; }
    .formatter-panels { grid-template-columns: 1fr; height: auto; }
    .panel { min-height: 300px; }
    .json-textarea { min-height: 300px; }
}

/* ============================================================
   Static pages (Terms, Privacy, Contact)
   ============================================================ */
.static-page {
    max-width: 760px;
    margin: 40px auto;
    padding: 0 20px 60px;
}

.static-page h1 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-heading);
    margin-bottom: 4px;
}

.static-page .subtitle {
    color: var(--text-muted);
    font-size: 0.875rem;
    margin-bottom: 32px;
}

.static-page section {
    margin-bottom: 28px;
}

.static-page h2 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-heading);
    margin-bottom: 10px;
}

.static-page p {
    line-height: 1.75;
    color: var(--text-primary);
    margin-bottom: 10px;
}

.static-page ul {
    padding-left: 20px;
    line-height: 1.75;
    color: var(--text-primary);
}

.static-page ul li { margin-bottom: 4px; }

.static-page a {
    color: var(--brand-color);
    text-decoration: none;
}

.static-page a:hover { text-decoration: underline; }

.contact-note {
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-left: 3px solid var(--brand-color);
    border-radius: 6px;
    padding: 14px 16px;
}

.contact-note p { margin: 0; }
