*{
    box-sizing: border-box;
}
:root {
    --apple-background: #f5f5f7;
    --card-background: #ffffff;
    --text-primary: #1d1d1f;
    --text-secondary: #6e6e73;
    --accent-blue: #0071e3;
    --border-color: #d2d2d7;
    --hover-light-gray: #f0f0f0;
    --apple-red: #d93d2b;
    --warning-orange: #f5a623;
    --warning-orange-bg: #fffbe6;
}

.no-copy {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    margin: 0;
    padding: 0;
    background-color: var(--apple-background);
    color: var(--text-primary);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.navbar {
    background-color: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-color);
    padding: 0 30px;
    height: 70px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-sizing: border-box;
    gap: 20px;
    position: relative;
    z-index: 1000;
}

.navbar-brand { display: flex; align-items: center; gap: 15px; }
.navbar-title { font-size: 1.15em; font-weight: 600; margin: 0; flex-shrink: 0; }
.navbar-title-link { color: inherit; text-decoration: none; }
.navbar-actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.navbar-button { background-color: var(--card-background); color: var(--text-primary); border: 1px solid var(--border-color); padding: 8px 15px; border-radius: 12px; font-family: inherit; font-size: 0.85em; font-weight: 500; cursor: pointer; transition: background-color 0.2s ease; }
.navbar-button:hover { background-color: var(--hover-light-gray); }
.navbar-link { background-color: var(--accent-blue); color: white; padding: 8px 15px; text-decoration: none; border-radius: 12px; font-weight: 500; font-size: 0.85em; transition: background-color 0.2s ease; }
.navbar-link:hover { background-color: #0056b3; }

.navbar-dropdown { position: relative; }
.navbar-dropdown-menu { display: none; flex-direction: column; gap: 4px; position: absolute; top: calc(100% + 8px); right: 0; min-width: 190px; background-color: var(--card-background); border: 1px solid var(--border-color); border-radius: 12px; padding: 6px; box-shadow: 0 10px 30px rgba(0,0,0,0.15); z-index: 1100; }
.navbar-dropdown-menu.is-open { display: flex; }
.navbar-dropdown-item { display: block; width: 100%; box-sizing: border-box; background: none; border: none; text-align: left; color: var(--text-primary); padding: 8px 12px; border-radius: 8px; font-family: inherit; font-size: 0.85em; font-weight: 500; cursor: pointer; text-decoration: none; transition: background-color 0.2s ease; }
.navbar-dropdown-item:hover { background-color: var(--hover-light-gray); }
.claude-icon { width: 14px; height: 14px; color: #D97757; vertical-align: -2px; margin: 0 2px; flex-shrink: 0; }

.modal-content-wide { width: 92%; max-width: 900px; margin: 6vh auto; max-height: 88vh; overflow-y: auto; }
.claude-info-steps { margin: 0; padding-left: 20px; color: var(--text-primary); line-height: 1.6; }
.claude-info-steps li { margin-bottom: 10px; }
.claude-info-steps li:last-child { margin-bottom: 0; }

.claude-instruction-wrapper { position: relative; margin: 8px 0 16px; }
.claude-instruction {
    max-height: 260px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-word;
    background-color: var(--hover-light-gray);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 16px;
    padding-top: 44px;
    margin: 0;
    font-family: "SFMono-Regular", Consolas, Menlo, monospace;
    font-size: 0.82em;
    line-height: 1.5;
}
.copy-instruction-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 1;
    background-color: var(--accent-blue);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 6px 12px;
    font-size: 0.8em;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s ease;
}
.copy-instruction-btn:hover { background-color: #0060c2; }
.copy-instruction-btn.is-copied { background-color: #34c759; }

.search-container { flex-grow: 1; display: flex; justify-content: center; }
.search-form { width: 100%; max-width: 450px; }
.search-form input[type="search"] { width: 100%; padding: 10px 15px 10px 40px; border: none; background-color: #e8e8ed; border-radius: 10px; box-sizing: border-box; font-size: 0.95em; font-family: inherit; transition: background-color 0.2s ease, box-shadow 0.2s ease; background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="%236e6e73" viewBox="0 0 16 16"><path d="M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001c.03.04.062.078.098.115l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85a1.007 1.007 0 0 0-.115-.1zM12 6.5a5.5 5.5 0 1 1-11 0 5.5 5.5 0 0 1 11 0z"/></svg>'); background-repeat: no-repeat; background-position: 12px center; }
.search-form input[type="search"]:focus { outline: none; box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.3); background-color: var(--card-background); }

.main-container { display: flex; height: calc(100vh - 70px); padding: 20px; gap: 20px; box-sizing: border-box; }
.content { background-color: var(--card-background); border-radius: 18px; padding: 25px; overflow-y: auto; box-sizing: border-box; flex: 1; }

.sidebar {
    background-color: var(--card-background);
    border-radius: 18px;
    padding: 25px;
    box-sizing: border-box;
    flex: 0 0 280px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: transform 0.3s ease-in-out;
}

.sidebar h2 {
    font-size: 1.8em;
    font-weight: 600;
    margin: 0 0 20px 0;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.sidebar ul {
    list-style-type: none;
    padding: 0;
    margin: 0;
    flex-grow: 1;
    overflow-y: auto;
}

.sidebar-item {
    position: relative;
    margin-bottom: 4px;
}

.sidebar-item .class-link {
    display: block;
    padding: 10px 40px 10px 15px;
    color: var(--text-primary);
    text-decoration: none;
    border-radius: 10px;
    font-weight: 500;
    font-size: 0.85em;
    line-height: 1.4;
    min-height: 2.2em;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.sidebar-item .class-link:hover { background-color: var(--hover-light-gray); }
.sidebar-item .class-link.active { background-color: var(--accent-blue); color: white; font-weight: 600; }

.content-header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
}
.content-header h2 {
    margin: 0; 
}

.welcome-message { text-align: center; padding: 50px; margin-top: 10%; color: var(--text-secondary); }
.welcome-message h2 { border: none; font-size: 2.5em; color: var(--text-primary); }

.delete-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background-color: var(--border-color);
    color: var(--text-secondary);
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    font-size: 18px;
    font-weight: bold;
    line-height: 1;
    text-align: center;
    cursor: pointer;
    text-decoration: none;
    margin-left: 10px;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.delete-btn:hover {
    background-color: var(--apple-red);
    color: white;
}

.sidebar-item .delete-btn {
    position: absolute;
    top: 50%;
    right: 12px;
    transform: translateY(-50%);
    background-color: transparent;
    color: var(--text-secondary);
    opacity: 0.6;
    margin-left: 0;
    transition: opacity 0.2s ease, background-color 0.2s ease, color 0.2s ease;
}

.sidebar-item:hover .delete-btn {
    opacity: 1;
}

.sidebar-item .delete-btn:hover {
    background-color: var(--apple-red);
    color: white;
    opacity: 1;
}

.modal { display: none; position: fixed; z-index: 1050; left: 0; top: 0; width: 100%; height: 100%; overflow: auto; background-color: rgba(0,0,0,0.5); backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px); }
.modal-content { background-color: var(--card-background); margin: 15vh auto; padding: 30px; border-radius: 18px; width: 90%; max-width: 900px; position: relative; box-shadow: 0 5px 25px rgba(0,0,0,0.2); animation: slideIn 0.3s ease-out; }
@keyframes slideIn { from { transform: translateY(-30px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal-content h3 { font-size: 1.5em; margin-top: 0; color: var(--text-primary); }
.close-btn { color: var(--border-color); position: absolute; top: 15px; right: 25px; font-size: 28px; font-weight: bold; transition: color 0.2s ease; }
.close-btn:hover, .close-btn:focus { color: var(--text-secondary); text-decoration: none; cursor: pointer; }
.action-button { display: block; width: 100%; box-sizing: border-box; background-color: var(--hover-light-gray); color: var(--text-primary); padding: 12px 20px; border: none; border-radius: 12px; cursor: pointer; font-size: 0.95em; font-weight: 500; margin-top: 10px; text-align: center; text-decoration: none; transition: background-color 0.2s ease; }
.action-button:hover { background-color: var(--border-color); }

.import-note {
    font-size: 0.9em;
    color: var(--text-secondary);
    margin-bottom: 15px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
}
.modal-content form input[type="file"] {
    display: block;
    width: 100%;
    padding: 10px;
    margin-bottom: 15px;
    border: 1px dashed var(--border-color);
    border-radius: 12px;
    background-color: var(--apple-background);
    cursor: pointer;
}

.modal-form label {
    display: block;
    margin: 15px 0 8px 0;
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 0.9em;
}

.modal-form input[type="text"],
.modal-form input[type="number"],
.modal-form input[type="password"],
.modal-form textarea,
.modal-form select {
    width: 100%;
    padding: 12px 15px;
    border: 1px solid var(--border-color);
    background-color: var(--apple-background);
    border-radius: 12px;
    box-sizing: border-box;
    font-size: 1em;
    font-family: inherit;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.modal-form textarea { resize: vertical; min-height: 60px; }

.modal-form input:focus,
.modal-form textarea:focus,
.modal-form select:focus {
    outline: none;
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.3);
}

.modal-form .action-button {
    width: 100%;
    margin-top: 25px;
    background-color: var(--accent-blue);
    color: white;
}
.modal-form .action-button:hover { background-color: #0056b3; }

.sidebar-action-box {
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.sidebar-action-btn {
    width: 100%;
    background-color: var(--hover-light-gray);
    border: none;
    color: var(--text-primary);
    padding: 12px;
    border-radius: 12px;
    font-size: 0.95em;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: background-color 0.2s ease;
}
.sidebar-action-btn:hover { background-color: var(--border-color); }

.header-action-btn {
    background-color: #333;
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-size: 0.95em;
    font-weight: 500;
    font-family: inherit;
    transition: background-color 0.2s ease;
    flex-shrink: 0;
    text-decoration: none;
}
.header-action-btn:hover { background-color: #000; }
.header-action-btn.delete { background-color: var(--apple-red); }
.header-action-btn.delete:hover { background-color: #a7281a; }

.editable-container { flex-grow: 1; min-width: 0; }
.editable-container.main-header .display-view h2 { margin: 0; }
.display-view { display: flex; align-items: center; gap: 10px; width: 100%; }
.display-view .term-text { flex-grow: 1; }
.edit-pencil-btn { background: none; border: none; cursor: pointer; font-size: 1.2em; color: var(--text-secondary); padding: 5px; border-radius: 5px; transition: background-color 0.2s, color 0.2s; flex-shrink: 0; }
.edit-pencil-btn:hover { background-color: var(--hover-light-gray); color: var(--text-primary); }

.inline-edit-form { display: flex; gap: 10px; align-items: center; width: 100%; }
.inline-edit-form input[type="text"] { flex-grow: 1; font-size: 1em; font-weight: normal; padding: 5px 10px; border: 1px solid var(--border-color); border-radius: 10px; }
.main-header .inline-edit-form input[type="text"] { font-size: 1.8em; font-weight: 600; }
.inline-edit-form button { background-color: var(--accent-blue); color: white; padding: 8px 16px; border: none; border-radius: 10px; cursor: pointer; font-size: 0.9em; font-weight: 500; transition: background-color 0.2s ease; flex-shrink: 0; }
.inline-edit-form button:hover { background-color: #0056b3; }

.subclass-block { margin-bottom: 25px; padding: 20px; border-radius: 12px; background-color: var(--apple-background); }
.subclass-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; }
.subclass-header h3 { margin: 0; color: var(--text-primary); font-size: 1.2em; font-weight: 600; }
.delete-btn.subclass { background-color: transparent; }
.delete-btn.subclass:hover { background-color: var(--apple-red); }

.term-list { list-style-type: none; padding-left: 0; margin: 0; }
.term-item-empty { color: var(--text-secondary); padding: 10px; text-align: center; }

.term-item {
    display: flex;
    align-items: center;
    gap: 15px;
    background-color: var(--card-background);
    margin-bottom: 8px;
    padding: 2px 15px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
}

.basket-table { width: 100%; border-collapse: collapse; margin-top: 20px; }
.basket-table th, .basket-table td { padding: 12px 15px; border-bottom: 1px solid var(--border-color); text-align: left; vertical-align: middle; }
.basket-table th { font-weight: 600; color: var(--text-secondary); }
.basket-table td:last-child { text-align: right; }

.term-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.addable-term { position: relative; cursor: pointer; transition: background-color 0.2s ease-out, border-color 0.2s ease-out; }
.addable-term:hover { background-color: #e9f5ff; }
.addable-term.added { background-color: #e8f5e9; }
.term-text { position: relative; text-align: left; }
.addable-term.added .term-text::after { content: '✔'; color: #28a745; font-size: 1em; font-weight: bold; display: inline-block; margin-left: 12px; vertical-align: middle; }
.addable-term.adding { opacity: 0.7; cursor: wait; }

.header-actions-group { display: flex; gap: 10px; }
.info-text { text-align: center; padding: 20px; color: var(--text-secondary); }
.config-table-modal { width: 100%; border-collapse: collapse; margin-top: 15px; }
.config-table-modal td { padding: 12px 5px; border-bottom: 1px solid var(--border-color); vertical-align: middle; }
.config-table-modal tr:last-child td { border-bottom: none; }
.config-table-modal td:first-child { font-weight: 500; }
.config-actions { text-align: right; display: flex; justify-content: flex-end; gap: 8px; }
.config-actions form, .config-actions a { display: inline-block; }
.action-btn-small { padding: 6px 14px; font-size: 0.9em; border-radius: 8px; cursor: pointer; text-decoration: none; border: none; font-family: inherit; font-weight: 500; transition: transform 0.2s ease, opacity 0.2s ease; }
.action-btn-small:hover { transform: scale(1.05); opacity: 0.9; }
.load-btn { background-color: var(--accent-blue); color: white; }
.delete-config-btn { background-color: var(--apple-red); color: white; }

.subclass-header { transition: background-color 0.2s ease-out; }
.addable-subclass { cursor: pointer; }
.addable-subclass:not(.added):hover { background-color: #e9f5ff; }
.addable-subclass.adding { opacity: 0.7; cursor: wait; }
.addable-subclass.added { background-color: #e8f5e9; }
.addable-subclass.added .display-view h3 { position: relative; display: inline-block; }
.addable-subclass.added .display-view h3::after { content: '✔'; color: #28a745; font-size: 0.8em; font-weight: bold; display: inline-block; margin-left: 12px; vertical-align: middle; }

.noselect { -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; }

#bulk-actions-bar { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background-color: rgba(29, 29, 31, 0.9); backdrop-filter: blur(15px); -webkit-backdrop-filter: blur(15px); color: white; padding: 15px 25px; border-radius: 18px; box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3); z-index: 999; display: flex; align-items: center; gap: 20px; animation: fadeInBottom 0.3s ease-out; }
@keyframes fadeInBottom { from { transform: translate(-50%, 20px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }
#bulk-actions-bar .selected-info { font-weight: 500; white-space: nowrap; }
#bulk-actions-bar #selected-count { font-weight: 700; }
#bulk-actions-bar form { display: flex; align-items: center; gap: 10px; }
#bulk-actions-bar select { background-color: #333; color: white; border: 1px solid #555; border-radius: 10px; padding: 8px 12px; font-family: inherit; font-size: 0.9em; }
#bulk-actions-bar button { background-color: var(--accent-blue); color: white; padding: 8px 18px; border: none; border-radius: 10px; cursor: pointer; font-size: 0.9em; font-weight: 500; transition: background-color 0.2s ease; }
#bulk-actions-bar button:hover { background-color: #0056b3; }
#bulk-actions-bar .delete-bulk-btn { background-color: var(--apple-red); }
#bulk-actions-bar .delete-bulk-btn:hover { background-color: #a7281a; }

.subclass-title-wrapper { flex-grow: 1; display: flex; align-items: center; gap: 15px; min-width: 0; }

.term-item input[type="checkbox"], .subclass-header input[type="checkbox"] {
    flex-shrink: 0;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    background-color: transparent;
    margin: 0;
    font: inherit;
    color: currentColor;
    width: 1.15em;
    height: 1.15em;
    border: 0.15em solid var(--border-color);
    border-radius: 0.35em;
    transform: translateY(-0.075em);
    display: grid;
    place-content: center;
}

.term-item input[type="checkbox"]::before, .subclass-header input[type="checkbox"]::before {
    content: "";
    width: 0.65em;
    height: 0.65em;
    transform: scale(0);
    transition: 120ms transform ease-in-out;
    box-shadow: inset 1em 1em var(--accent-blue);
    background-color: CanvasText;
    transform-origin: bottom left;
    clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
}

.term-item input[type="checkbox"]:checked::before, .subclass-header input[type="checkbox"]:checked::before { transform: scale(1); }
.term-item input[type="checkbox"]:checked, .subclass-header input[type="checkbox"]:checked { border-color: var(--accent-blue); }
.term-item input[type="checkbox"]:focus { outline: max(2px, 0.15em) solid currentColor; outline-offset: max(2px, 0.15em); }

.term-item.is-duplicate { border-left: 4px solid var(--warning-orange); }
.addable-term.is-duplicate:hover { background-color: #fff5cc; }

.duplicate-badge { background-color: var(--warning-orange); color: var(--text-primary); font-size: 0.75em; font-weight: 600; padding: 3px 8px; border-radius: 980px; text-transform: uppercase; letter-spacing: 0.5px; white-space: nowrap; }

.drag-handle { cursor: grab; color: var(--border-color); font-size: 1.5em; line-height: 1; padding: 0 5px; transition: color 0.2s ease; }
.drag-handle:hover { color: var(--text-secondary); }
.term-item.sortable-ghost { background: #e9f5ff; border: 2px dashed var(--accent-blue); opacity: 0.7; }
.term-item.sortable-chosen { cursor: grabbing; box-shadow: 0 5px 15px rgba(0,0,0,0.15); }

.toggle-manual-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.2em;
    color: var(--border-color);
    padding: 5px;
    border-radius: 5px;
    transition: color 0.2s ease, transform 0.2s ease;
}
.toggle-manual-btn:hover {
    color: var(--warning-orange);
    transform: scale(1.1);
}
.term-item.is-manual .toggle-manual-btn {
    color: var(--warning-orange);
}
.term-item.is-manual {
    background-color: var(--warning-orange-bg);
    border-color: var(--warning-orange);
}

.mobile-nav-toggle {
    display: none;
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    width: 40px;
    height: 40px;
    cursor: pointer;
    font-size: 24px;
    color: var(--text-secondary);
}
.mobile-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.4);
    z-index: 1001;
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
}
.mobile-overlay.is-visible {
    display: block;
    opacity: 1;
}


@media (max-width: 1024px) {
    body {
        overflow: auto;
    }
    .navbar {
        flex-wrap: wrap;
        height: auto;
        padding: 10px 15px;
        gap: 10px;
    }
    .navbar-brand {
        width: 100%;
        justify-content: space-between;
    }
    .search-container {
        order: 3;
        width: 100%;
        justify-content: flex-start;
    }
    .search-form {
        max-width: none;
    }
    .navbar-actions {
        order: 2;
        flex-grow: 1;
        justify-content: flex-end;
    }

    .mobile-nav-toggle {
        display: block;
        order: -1; 
    }
    
    .main-container {
        display: block;
        height: auto;
        padding: 15px;
    }
    
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100%;
        z-index: 1002;
        transform: translateX(-100%);
        width: 300px;
        max-width: 80%;
        border-radius: 0 18px 18px 0;
        border-right: 1px solid var(--border-color);
        box-shadow: 5px 0 25px rgba(0,0,0,0.1);
    }
    .sidebar.is-visible {
        transform: translateX(0);
    }
    .content {
        padding: 15px;
    }
}

@media (max-width: 600px) {
    .navbar-actions .navbar-button, 
    .navbar-actions .navbar-link {
        padding: 8px 10px;
        font-size: 0.8em;
    }
    .header-actions-group {
        width: 100%;
        justify-content: space-between;
    }
    .header-actions-group .header-action-btn {
        flex-grow: 1;
        text-align: center;
    }
    #bulk-actions-bar {
        flex-direction: column;
        gap: 15px;
        padding: 15px;
        width: calc(100% - 30px);
        bottom: 10px;
    }
    #bulk-actions-bar form {
        width: 100%;
    }
    #bulk-actions-bar select, #bulk-actions-bar button {
        width: 100%;
        text-align: center;
    }
    #bulk-actions-bar .delete-bulk-btn {
        margin-top: 5px;
    }
}