:root {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: #0f172a;
    background-color: #f8fafc;
}

body {
    margin: 0;
    padding: 0 1rem 2rem;
}

header {
    text-align: center;
    padding: 0.05rem 0;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

header h1 {
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.header-logo {
    width: 32px;
    height: 32px;
}

.header-link {
    text-decoration: none;
    color: inherit;
    cursor: pointer;
    transition: opacity 0.2s ease;
}

.header-link:hover {
    opacity: 0.7;
}

.theme-toggle {
    position: absolute;
    right: 0;
    background: none;
    border: 1px solid #cbd5f5;
    border-radius: 8px;
    width: 40px;
    height: 40px;
    cursor: pointer;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.theme-icon-dark {
    display: none;
}

body.dark-mode .theme-icon-light {
    display: none;
}

body.dark-mode .theme-icon-dark {
    display: inline;
}

main {
    max-width: 1100px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.form-section,
.entries,
.suggestions {
    background: white;
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

.suggestions-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.suggestions-header h2 {
    margin: 0;
}

.suggestions-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #64748b;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.suggestions-close:hover {
    color: #0f172a;
}

.form-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.form-section h2 {
    font-size: 1.3rem;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.section-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.subtle-button {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.75rem;
    font-size: 0.85rem;
    color: #64748b;
    background: transparent;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s ease;
}

.subtle-button:hover {
    color: #334155;
    background: #f1f5f9;
    border-color: #cbd5e1;
}

.subtle-button .toggle-icon {
    font-size: 0.7rem;
    transition: transform 0.2s ease;
}

.subtle-button .toggle-icon.expanded {
    transform: rotate(180deg);
}

body.dark-mode .subtle-button {
    color: #94a3b8;
    border-color: #334155;
}

body.dark-mode .subtle-button:hover {
    color: #e2e8f0;
    background: #1e293b;
    border-color: #475569;
}

.form-grid {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.input-row {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
}

label {
    display: flex;
    flex-direction: column;
    font-size: 0.9rem;
    font-weight: 600;
    gap: 0.3rem;
}

.icon-label input[type="number"],
.icon-label input[type="text"],
.icon-label input[type="time"],
.icon-label input[type="date"] {
    width: 140px;
    max-width: 100%;
}

.icon-label input,
.icon-label textarea {
    align-self: flex-start;
}

.icon-label span:first-child {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.textarea-row {
    display: flex;
    flex-wrap: wrap;
    gap: 2rem;
}

.textarea-row .icon-label {
    flex: 1 1 0;
    min-width: 240px;
}

.icon-label.wide textarea {
    width: 100%;
    align-self: stretch;
    min-width: 320px;
}

input, textarea {
    border: 1px solid #cbd5f5;
    border-radius: 8px;
    padding: 0.5rem;
    font-size: 1rem;
    font-family: inherit;
}

textarea {
    resize: vertical;
}

.checkbox {
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
    margin: 1rem 0;
}

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

button {
    background: #f97316;
    color: white;
    border: none;
    border-radius: 8px;
    padding: 0.7rem 1.4rem;
    font-size: 1rem;
    cursor: pointer;
}

.ghost-button {
    background: #f1f5f9;
    color: #0f172a;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 0.7rem 1.4rem;
    font-size: 1rem;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    transition: background 0.2s;
}

.ghost-button:hover {
    background: #e2e8f0;
}

.secondary-button {
    background: #2563eb;
    color: #ffffff;
    border: none;
}

.table-wrapper {
    overflow-x: auto;
    overflow-y: auto;
    max-height: 75vh;
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead {
    position: sticky;
    top: 0;
    z-index: 1;
}

th {
    background: white;
}

th, td {
    border-bottom: 1px solid #e2e8f0;
    padding: 0.5rem;
    text-align: left;
    font-size: 0.9rem;
}

.actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.link-button,
.icon-button {
    border: none;
    background: none;
    cursor: pointer;
    padding: 0;
}

.icon-button {
    color: #2563eb;
    font-size: 1.1rem;
    line-height: 1;
}

.icon-button.danger,
.link-button {
    color: #dc2626;
}

.details-row {
    display: none;
    background: #eef2ff;
}

.details-row.show {
    display: table-row;
}

.details-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    font-size: 0.9rem;
}

.details-grid strong {
    display: block;
    margin-bottom: 0.2rem;
}

.details-grid p {
    margin: 0;
    white-space: pre-wrap;
}

.flash-messages {
    list-style: none;
    padding: 0;
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.flash {
    background: #0f172a;
    color: white;
    padding: 0.8rem 1.2rem;
    margin: 0;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    animation: toast-pop 2.5s ease-in-out forwards;
    font-size: 0.9rem;
}

.flash.success {
    background: #16a34a;
}

.flash.info {
    background: #2563eb;
}

.flash.warning {
    background: #f97316;
}

@keyframes toast-pop {
    0% { opacity: 0; transform: translateX(100%); }
    10% { opacity: 1; transform: translateX(0); }
    80% { opacity: 1; transform: translateX(0); }
    100% { opacity: 0; transform: translateX(100%); }
}

.time-field .time-wrapper {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.refresh-button {
    border: 1px solid #cbd5f5;
    background: #f8fafc;
    color: #2563eb;
    border-radius: 8px;
    padding: 0;
    width: 39px;
    height: 39px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.datetime-wrapper {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    align-items: flex-end;
}

.datetime-box {
    display: inline-flex;
    gap: 0.8rem;
    border: 1px solid #cbd5f5;
    border-radius: 12px;
    padding: 0.6rem 0.8rem;
    background: #fff;
    align-items: flex-end;
}

.datetime-box .icon-label {
    margin: 0;
}

.datetime-box .icon-label input {
    width: 140px;
}

.chart-trigger {
    cursor: pointer;
    transition: color 0.2s;
}

.chart-trigger:hover {
    color: #2563eb;
    text-decoration: underline;
}

.chart-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.chart-modal.show {
    display: flex;
}

.chart-modal-content {
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(15, 23, 42, 0.2);
    width: 90%;
    max-width: 800px;
    max-height: 90vh;
    overflow: hidden;
}

.chart-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid #e2e8f0;
}

.chart-modal-header h3 {
    margin: 0;
    font-size: 1.2rem;
}

.chart-modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #64748b;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chart-modal-close:hover {
    color: #0f172a;
}

.chart-controls {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    flex-wrap: wrap;
    gap: 0.8rem;
    align-items: center;
}

.chart-quick-filters {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.chart-filter-btn {
    background: #f1f5f9;
    color: #0f172a;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 0.45rem 0.8rem;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
    height: 36px;
    box-sizing: border-box;
}

.chart-filter-btn:hover {
    background: #e2e8f0;
}

.chart-filter-btn.active {
    background: #2563eb;
    color: white;
    border-color: #2563eb;
}

.chart-date-range {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin-left: auto;
}

.chart-date-range label {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.85rem;
    font-weight: normal;
}

.chart-date-range input[type="date"] {
    padding: 0.45rem 0.5rem;
    font-size: 0.85rem;
    width: auto;
    height: 36px;
    box-sizing: border-box;
}

.chart-apply-btn {
    background: #f97316;
    color: white;
    border: none;
    border-radius: 6px;
    padding: 0.45rem 0.8rem;
    font-size: 0.85rem;
    cursor: pointer;
    height: 36px;
    box-sizing: border-box;
}

.chart-apply-btn:hover {
    background: #ea580c;
}

.chart-container {
    padding: 1.5rem;
    height: 400px;
}

/* Dark Mode */
body.dark-mode {
    background-color: #0f172a;
    color: #e2e8f0;
}

body.dark-mode .form-section,
body.dark-mode .entries,
body.dark-mode .suggestions {
    background: #1e293b;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

body.dark-mode input,
body.dark-mode textarea {
    background: #334155;
    border-color: #475569;
    color: #e2e8f0;
}

body.dark-mode input::placeholder,
body.dark-mode textarea::placeholder {
    color: #94a3b8;
}

body.dark-mode .theme-toggle {
    background: #334155;
    border-color: #475569;
    color: #e2e8f0;
}

body.dark-mode .refresh-button {
    background: #334155;
    border-color: #475569;
    color: #60a5fa;
}

body.dark-mode .datetime-box {
    background: #1e293b;
    border-color: #475569;
}

body.dark-mode .ghost-button {
    background: #334155;
    color: #e2e8f0;
    border-color: #475569;
}

body.dark-mode .ghost-button:hover {
    background: #475569;
}

body.dark-mode table th {
    background: #1e293b;
}

body.dark-mode table th,
body.dark-mode table td {
    border-bottom-color: #334155;
}

body.dark-mode .details-row {
    background: #334155;
}

body.dark-mode .icon-button {
    color: #60a5fa;
}

body.dark-mode .icon-button.danger {
    color: #f87171;
}

body.dark-mode .chart-modal-content {
    background: #1e293b;
}

body.dark-mode .chart-modal-header {
    border-bottom-color: #334155;
}

body.dark-mode .chart-modal-header h3 {
    color: #e2e8f0;
}

body.dark-mode .chart-modal-close {
    color: #94a3b8;
}

body.dark-mode .chart-modal-close:hover {
    color: #e2e8f0;
}

body.dark-mode .chart-controls {
    border-bottom-color: #334155;
}

body.dark-mode .chart-filter-btn {
    background: #334155;
    color: #e2e8f0;
    border-color: #475569;
}

body.dark-mode .chart-filter-btn:hover {
    background: #475569;
}

body.dark-mode .chart-date-range label {
    color: #e2e8f0;
}

body.dark-mode .chart-date-range input[type="date"] {
    background: #334155;
    border-color: #475569;
    color: #e2e8f0;
    color-scheme: dark;
}

body.dark-mode .suggestions-close {
    color: #94a3b8;
}

body.dark-mode .suggestions-close:hover {
    color: #e2e8f0;
}

/* Suggestions Modal */
.suggestions-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.suggestions-modal.show {
    display: flex;
}

.suggestions-modal-content {
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(15, 23, 42, 0.2);
    width: 90%;
    max-width: 700px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}

.suggestions-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid #e2e8f0;
}

.suggestions-modal-header h3 {
    margin: 0;
    font-size: 1.1rem;
}

.suggestions-modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #64748b;
    padding: 0;
}

.suggestions-modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 0 0 auto;
}

.modal-input-row {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
}

.suggestions-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
}

.suggestions-option-group {
    margin-bottom: 0;
}

.suggestions-option-group h4 {
    margin: 0 0 0.8rem 0;
    font-size: 0.95rem;
    color: #475569;
}

.suggestions-checkbox {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.6rem;
    padding: 0.5rem 0;
    cursor: pointer;
    font-weight: normal;
}

.suggestions-checkbox input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.suggestions-checkbox span {
    font-size: 0.9rem;
}

.suggestions-preview {
    padding: 1rem 1.5rem;
    border-top: 1px solid #e2e8f0;
    flex: 1 1 auto;
    overflow-y: auto;
    min-height: 0;
}

.suggestions-preview h4 {
    margin: 0 0 0.8rem 0;
    font-size: 0.95rem;
    color: #475569;
}

.suggestions-preview-content {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 1rem;
    font-size: 0.85rem;
    white-space: pre-wrap;
    font-family: monospace;
    display: block;
    word-wrap: break-word;
}

.suggestions-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.8rem;
    padding: 1rem 1.5rem;
    border-top: 1px solid #e2e8f0;
    flex-shrink: 0;
}

body.dark-mode .suggestions-modal-content {
    background: #1e293b;
}

body.dark-mode .suggestions-modal-header {
    border-bottom-color: #334155;
}

body.dark-mode .suggestions-modal-header h3 {
    color: #e2e8f0;
}

body.dark-mode .suggestions-modal-close {
    color: #94a3b8;
}

body.dark-mode .suggestions-option-group h4 {
    color: #94a3b8;
}

body.dark-mode .suggestions-checkbox span {
    color: #e2e8f0;
}

body.dark-mode .suggestions-modal-footer {
    border-top-color: #334155;
}

body.dark-mode .suggestions-preview {
    border-top-color: #334155;
}

body.dark-mode .suggestions-preview h4 {
    color: #94a3b8;
}

body.dark-mode .suggestions-preview-content {
    background: #334155;
    border-color: #475569;
    color: #e2e8f0;
}

/* Primary Button (used in sync settings) */
.primary-button {
    background: #2563eb;
    color: white;
    border: none;
    border-radius: 8px;
    padding: 0.7rem 1.4rem;
    font-size: 1rem;
    cursor: pointer;
}

.primary-button:hover {
    background: #1d4ed8;
}

/* Trend Icons */
.trend-cell {
    position: relative;
    white-space: nowrap;
}

.trend-icon {
    display: none;
    margin-left: 0.25rem;
    font-size: 0.75rem;
}

.trends-visible .trend-icon {
    display: inline;
}

.trend-icon.positive {
    color: #16a34a;
}

.trend-icon.negative {
    color: #dc2626;
}

.trend-icon.neutral {
    color: #94a3b8;
}

/* Dark mode for trends */
body.dark-mode .trend-icon.positive {
    color: #4ade80;
}

body.dark-mode .trend-icon.negative {
    color: #f87171;
}

/* Login Form */
.login-container {
    max-width: 400px;
    margin: 4rem auto;
    background: white;
    border-radius: 12px;
    padding: 2rem;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

.login-container.config-help {
    max-width: 600px;
}

.login-container.config-help h3 {
    font-size: 1rem;
    margin: 1.5rem 0 0.5rem 0;
    color: #475569;
}

.login-container.config-help h3:first-of-type {
    margin-top: 1rem;
}

body.dark-mode .login-container.config-help h3 {
    color: #94a3b8;
}

.login-container h2 {
    margin: 0 0 1.5rem 0;
    text-align: center;
    font-size: 1.5rem;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.login-form .form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.login-form input[type="password"] {
    width: 100%;
    box-sizing: border-box;
    padding: 0.75rem;
    font-size: 1rem;
}

.login-form .btn-primary {
    background: #2563eb;
    color: white;
    border: none;
    border-radius: 8px;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    cursor: pointer;
    margin-top: 0.5rem;
}

.login-form .btn-primary:hover {
    background: #1d4ed8;
}

body.dark-mode .login-container {
    background: #1e293b;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.login-container .error-message {
    color: #64748b;
    line-height: 1.6;
}

.login-container code {
    background: #f1f5f9;
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-size: 0.9rem;
}

.login-container pre {
    background: #f1f5f9;
    padding: 1rem;
    border-radius: 8px;
    overflow-x: auto;
    margin: 1rem 0;
}

.login-container pre code {
    background: none;
    padding: 0;
}

body.dark-mode .login-container pre {
    background: #334155;
}

body.dark-mode .login-container .error-message {
    color: #94a3b8;
}

body.dark-mode .login-container code {
    background: #334155;
}

.flash.error {
    background: #dc2626;
}

/* Logout Button */
.logout-btn {
    position: absolute;
    left: 0;
    background: none;
    border: 1px solid #cbd5f5;
    border-radius: 8px;
    width: 40px;
    height: 40px;
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    color: #64748b;
    text-decoration: none;
}

.logout-btn:hover {
    background: #f1f5f9;
    color: #0f172a;
}

/* Burger Menu */
.burger-menu-btn {
    position: absolute;
    left: 0;
    background: none;
    border: 1px solid #cbd5f5;
    border-radius: 8px;
    width: 40px;
    height: 40px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 8px;
}

.burger-line {
    display: block;
    width: 20px;
    height: 2px;
    background: #64748b;
    border-radius: 2px;
    transition: all 0.3s ease;
}

.burger-menu-btn.open .burger-line:nth-child(1) {
    transform: rotate(45deg) translate(5px, 5px);
}

.burger-menu-btn.open .burger-line:nth-child(2) {
    opacity: 0;
}

.burger-menu-btn.open .burger-line:nth-child(3) {
    transform: rotate(-45deg) translate(5px, -5px);
}

.burger-menu {
    display: none;
    position: absolute;
    top: 50px;
    left: 0;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.1);
    min-width: 180px;
    z-index: 100;
    overflow: hidden;
}

.burger-menu.show {
    display: block;
}

.burger-menu-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    color: #0f172a;
    text-decoration: none;
    border: none;
    background: none;
    width: 100%;
    font-size: 0.95rem;
    cursor: pointer;
    text-align: left;
}

.burger-menu-item:hover {
    background: #f1f5f9;
}

.burger-menu-item .theme-icon-dark,
.burger-menu-item .theme-text-dark {
    display: none;
}

body.dark-mode .burger-menu-item .theme-icon-light,
body.dark-mode .burger-menu-item .theme-text-light {
    display: none;
}

body.dark-mode .burger-menu-item .theme-icon-dark,
body.dark-mode .burger-menu-item .theme-text-dark {
    display: inline;
}

body.dark-mode .burger-menu-btn {
    border-color: #475569;
}

body.dark-mode .burger-line {
    background: #94a3b8;
}

body.dark-mode .burger-menu {
    background: #1e293b;
    border-color: #475569;
}

body.dark-mode .burger-menu-item {
    color: #e2e8f0;
}

body.dark-mode .burger-menu-item:hover {
    background: #334155;
}

/* Sync Settings Page */
.settings-section {
    background: white;
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

.settings-header {
    margin-bottom: 1.5rem;
}

.settings-header h2 {
    margin: 0;
    font-size: 1.3rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.settings-card {
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
}

.settings-card h3 {
    margin: 0 0 0.75rem 0;
    font-size: 1rem;
    color: #475569;
}

.settings-hint {
    font-size: 0.85rem;
    color: #64748b;
    margin: 0 0 1rem 0;
}

.device-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.device-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.9rem;
}

.device-option:hover {
    background: #f8fafc;
    border-color: #cbd5e1;
}

.device-option input[type="radio"] {
    margin: 0;
}

.device-label {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.device-badge {
    display: inline-block;
    font-size: 0.65rem;
    padding: 0.1rem 0.3rem;
    border-radius: 4px;
    margin-left: 0.25rem;
}

.device-badge.active {
    background: #dcfce7;
    color: #166534;
}

.device-badge.inactive {
    background: #fef3c7;
    color: #92400e;
}

.device-meta {
    font-size: 0.75rem;
    color: #64748b;
    margin-left: 0.5rem;
}

.no-devices {
    color: #64748b;
    font-style: italic;
}

.data-types-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.data-type-item {
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 0.75rem;
    background: white;
}

.data-type-row {
    display: flex;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 1rem;
}

.data-type-toggle {
    display: inline-flex !important;
    flex-direction: row !important;
    align-items: center !important;
    gap: 0.5rem;
    cursor: pointer;
    font-weight: normal;
    min-width: 180px;
    flex-shrink: 0;
    margin-top: 0.1rem;
}

.data-type-toggle input[type="checkbox"] {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    margin: 0 !important;
    display: inline-block !important;
}

.data-type-icon {
    font-size: 1rem;
    line-height: 1;
    display: inline !important;
}

.data-type-label {
    font-weight: 600;
    white-space: nowrap;
    line-height: 1;
    display: inline !important;
}

.data-type-options {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
}

.data-type-options.disabled {
    opacity: 0.4;
    pointer-events: none;
}

.option-label {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.25rem;
    font-size: 0.85rem;
    font-weight: normal;
}

.option-label span {
    color: #64748b;
    white-space: nowrap;
}

.option-label select {
    padding: 0.35rem 0.5rem;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 0.85rem;
}

.display-options {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
}

.checkbox-option {
    display: inline-flex !important;
    flex-direction: row !important;
    align-items: center !important;
    gap: 0.5rem;
    cursor: pointer;
    font-weight: normal;
    font-size: 0.9rem;
}

.checkbox-option input[type="checkbox"] {
    width: 16px;
    height: 16px;
    margin: 0 !important;
    flex-shrink: 0;
    display: inline-block !important;
}

.checkbox-option span {
    line-height: 1.2;
    display: inline !important;
}

.checkbox-option.sub-option {
    margin-left: 1.5rem;
}

.checkbox-option.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.checkbox-option.disabled input[type="checkbox"] {
    cursor: not-allowed;
}

.auto-sync-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.test-button {
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
}

.settings-hint.sub-hint {
    margin-top: 0.5rem;
    margin-left: 1.5rem;
    font-size: 0.8rem;
    opacity: 0.8;
}

.settings-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1rem;
}

/* Dark mode for settings */
body.dark-mode .settings-section {
    background: #1e293b;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

body.dark-mode .settings-card {
    border-color: #475569;
}

body.dark-mode .settings-card h3 {
    color: #94a3b8;
}

body.dark-mode .settings-hint {
    color: #94a3b8;
}

body.dark-mode .device-option {
    border-color: #475569;
}

body.dark-mode .device-option:hover {
    background: #334155;
}

body.dark-mode .device-badge.active {
    background: #064e3b;
    color: #6ee7b7;
}

body.dark-mode .device-badge.inactive {
    background: #78350f;
    color: #fcd34d;
}

body.dark-mode .data-type-item {
    border-color: #475569;
    background: #1e293b;
}

body.dark-mode .option-label span {
    color: #94a3b8;
}

body.dark-mode .option-label select {
    background: #334155;
    border-color: #475569;
    color: #e2e8f0;
}

/* Sync Button */
.sync-button {
    border: 1px solid #cbd5f5;
    background: #f8fafc;
    color: #2563eb;
    border-radius: 8px;
    padding: 0;
    width: 39px;
    height: 39px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.2s;
}

.sync-button:hover:not(:disabled) {
    background: #2563eb;
    color: white;
}

.sync-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.sync-button.syncing {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

body.dark-mode .sync-button {
    background: #334155;
    border-color: #475569;
    color: #60a5fa;
}

body.dark-mode .sync-button:hover:not(:disabled) {
    background: #2563eb;
    color: white;
}

/* Synced field highlight */
input.synced-field,
textarea.synced-field {
    background-color: #dbeafe !important;
    border-color: #3b82f6 !important;
    transition: background-color 0.3s, border-color 0.3s;
}

body.dark-mode input.synced-field,
body.dark-mode textarea.synced-field {
    background-color: #1e3a5f !important;
    border-color: #3b82f6 !important;
}

/* Sync info display */
.sync-info-panel {
    background: #f0f9ff;
    border: 1px solid #bae6fd;
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
    font-size: 0.85rem;
}

.sync-info-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.sync-info-panel h4 {
    margin: 0;
    font-size: 0.9rem;
    color: #0369a1;
}

.sync-panel-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: #0369a1;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    opacity: 0.7;
}

.sync-panel-close:hover {
    opacity: 1;
}

.sync-info-panel .sync-details {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.sync-info-panel .sync-detail-item {
    display: flex;
    justify-content: space-between;
    padding: 0.25rem 0;
    border-bottom: 1px solid #e0f2fe;
}

.sync-info-panel .sync-detail-item:last-child {
    border-bottom: none;
}

body.dark-mode .sync-info-panel {
    background: #0c4a6e;
    border-color: #0369a1;
}

body.dark-mode .sync-info-panel h4 {
    color: #7dd3fc;
}

body.dark-mode .sync-panel-close {
    color: #7dd3fc;
}

body.dark-mode .sync-info-panel .sync-detail-item {
    border-bottom-color: #075985;
}

/* Raw data display in sync panel */
.sync-raw-data {
    margin-top: 1rem;
    border-top: 1px solid #bae6fd;
    padding-top: 0.75rem;
}

.sync-raw-data details {
    cursor: pointer;
}

.sync-raw-data summary {
    font-weight: 600;
    color: #0369a1;
    padding: 0.5rem 0;
}

.sync-raw-data pre {
    background: #f0f9ff;
    border: 1px solid #bae6fd;
    border-radius: 6px;
    padding: 0.75rem;
    margin: 0.5rem 0 0 0;
    font-size: 0.75rem;
    overflow-x: auto;
    max-height: 300px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
}

body.dark-mode .sync-raw-data {
    border-top-color: #075985;
}

body.dark-mode .sync-raw-data summary {
    color: #7dd3fc;
}

body.dark-mode .sync-raw-data pre {
    background: #0c4a6e;
    border-color: #075985;
    color: #e0f2fe;
}

/* Info icon and tooltip */
.info-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #e0e7ff;
    color: #4f46e5;
    font-size: 12px;
    cursor: help;
    margin-left: 6px;
    position: relative;
    transition: background 0.2s, transform 0.2s;
}

.info-icon:hover {
    background: #c7d2fe;
    transform: scale(1.1);
}

/* Hide tooltip content by default */
.info-icon .tooltip-content {
    display: none;
}

/* Tooltip for single-line (data-tooltip attribute) */
.info-icon::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: #1e293b;
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    z-index: 1000;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

/* Multiline tooltip - show tooltip-content */
.info-icon[data-tooltip-multiline="true"]:hover .tooltip-content {
    display: block;
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: #1e293b;
    color: white;
    padding: 10px 14px;
    border-radius: 6px;
    font-size: 12px;
    white-space: nowrap;
    z-index: 1000;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.info-icon[data-tooltip-multiline="true"] .tooltip-content div {
    padding: 2px 0;
    line-height: 1.4;
}

/* Hide single-line tooltip for multiline icons */
.info-icon[data-tooltip-multiline="true"]::after {
    content: none;
}

.info-icon::before {
    content: '';
    position: absolute;
    bottom: calc(100% + 2px);
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: #1e293b;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    z-index: 1000;
}

.info-icon:hover::after,
.info-icon:hover::before {
    opacity: 1;
}

body.dark-mode .info-icon {
    background: #1e40af;
    color: #dbeafe;
}

body.dark-mode .info-icon:hover {
    background: #1e3a8a;
}

body.dark-mode .info-icon::after {
    background: #f8fafc;
    color: #1e293b;
}

body.dark-mode .info-icon[data-tooltip-multiline="true"]:hover .tooltip-content {
    background: #f8fafc;
    color: #1e293b;
}

/* AI Settings Page Styles */
.ai-provider-selection {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.radio-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    flex: 1;
}

.radio-option input[type="radio"] {
    cursor: pointer;
}

.radio-option:has(input:checked) {
    border-color: #2563eb;
    background: #eff6ff;
}

body.dark-mode .radio-option {
    border-color: #475569;
}

body.dark-mode .radio-option:has(input:checked) {
    border-color: #60a5fa;
    background: #1e3a8a;
}

.model-selection {
    margin-top: 1rem;
}

.model-list {
    max-height: 250px;
    overflow-y: auto;
    padding-right: 0.5rem;
}

.model-list h4 {
    margin: 0 0 1rem 0;
    font-size: 0.95rem;
    color: #475569;
    position: sticky;
    top: 0;
    background: white;
    padding: 0.5rem 0;
    z-index: 1;
}

body.dark-mode .model-list h4 {
    color: #94a3b8;
    background: #0f172a;
}

.model-option {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1rem;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
}

.model-option input[type="radio"] {
    cursor: pointer;
}

.model-option:has(input:checked) {
    border-color: #2563eb;
    background: #eff6ff;
}

body.dark-mode .model-option {
    border-color: #475569;
}

body.dark-mode .model-option:has(input:checked) {
    border-color: #60a5fa;
    background: #1e3a8a;
}

.model-name {
    font-weight: 600;
    font-size: 0.95rem;
}

.model-created {
    font-size: 0.85rem;
    color: #64748b;
    text-align: right;
}

body.dark-mode .model-created {
    color: #94a3b8;
}

.card-header-with-action {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.card-header-with-action h3 {
    margin: 0;
}

.question-header-with-action {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.question-header-with-action h4 {
    margin: 0;
    font-size: 1rem;
}

.small-button {
    background: #2563eb;
    color: white;
    border: none;
    border-radius: 6px;
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.2s;
}

.small-button:hover {
    background: #1d4ed8;
}

.prompt-select {
    width: 100%;
    padding: 0.6rem;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 0.95rem;
    margin-bottom: 0.75rem;
}

body.dark-mode .prompt-select {
    background: #334155;
    border-color: #475569;
    color: #e2e8f0;
}

.prompt-textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 0.9rem;
    font-family: 'Courier New', monospace;
    line-height: 1.5;
    resize: vertical;
    box-sizing: border-box;
}

.prompt-textarea[readonly] {
    background: #f8fafc;
    cursor: not-allowed;
}

body.dark-mode .prompt-textarea {
    background: #334155;
    border-color: #475569;
    color: #e2e8f0;
}

body.dark-mode .prompt-textarea[readonly] {
    background: #1e293b;
}

.prompt-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 0.75rem;
}

.danger-text {
    color: #dc2626;
}

.danger-text:hover {
    background: #fee2e2;
}

body.dark-mode .danger-text {
    color: #f87171;
}

body.dark-mode .danger-text:hover {
    background: #7f1d1d;
}

.context-question-group {
    margin-bottom: 1.5rem;
    padding: 1rem;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
}

body.dark-mode .context-question-group {
    border-color: #475569;
}

.question-select-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 0.75rem;
}

.context-question-select {
    flex: 1;
    padding: 0.5rem;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 0.9rem;
}

.question-count-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

.count-label {
    font-size: 0.9rem;
    color: #475569;
    font-weight: 500;
}

.question-count-input {
    width: 80px;
    padding: 0.4rem;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 0.9rem;
}

.question-count-input[readonly] {
    background: #f8fafc;
    cursor: not-allowed;
}

body.dark-mode .context-question-select {
    background: #334155;
    border-color: #475569;
    color: #e2e8f0;
}

body.dark-mode .count-label {
    color: #cbd5e1;
}

body.dark-mode .question-count-input {
    background: #334155;
    border-color: #475569;
    color: #e2e8f0;
}

body.dark-mode .question-count-input[readonly] {
    background: #1e293b;
}

.question-preview {
    width: 100%;
    padding: 0.6rem;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: 0.85rem;
    background: #f8fafc;
    resize: none;
    box-sizing: border-box;
}

.question-preview[readonly] {
    cursor: not-allowed;
}

body.dark-mode .question-preview {
    background: #1e293b;
    border-color: #475569;
    color: #e2e8f0;
}

.question-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.modal-input,
.modal-textarea {
    width: 100%;
    padding: 0.6rem;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 0.95rem;
    font-family: inherit;
    box-sizing: border-box;
}

.modal-textarea {
    resize: vertical;
    font-family: 'Courier New', monospace;
}

body.dark-mode .modal-input,
body.dark-mode .modal-textarea {
    background: #334155;
    border-color: #475569;
    color: #e2e8f0;
}
