/* Components: forms, lists, day pills, messages, tabs, modals, accordion */
/* Forms */
.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
    font-size: 14px;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    height: 40px;
    /* Standardize height */
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: #3498db;
}

.form-group textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    font-family: inherit;
    line-height: 1.5;
    resize: vertical;
}

.form-group textarea:focus {
    outline: none;
    border-color: #3498db;
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s;
    height: 40px;
    /* Standardize height */
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-primary {
    background: #2563eb;
    color: white;
}

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

.btn-danger {
    background: #c0392b;
    color: white;
}

.btn-danger:hover {
    background: #a93226;
}

.btn-secondary {
    background: #5b6b7a;
    color: white;
}

.btn-secondary:hover {
    background: #46545f;
}

.btn-sm {
    padding: 5px 12px;
    font-size: 12px;
    height: 30px;
    /* Smaller but standardized */
}

.btn:disabled {
    background: #ccc;
    cursor: not-allowed;
    opacity: 0.7;
}

/* Lists */
.item-list {
    list-style: none;
}

.item-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    border-bottom: 1px solid #eee;
}

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

.item-list .item-name {
    font-weight: 500;
}

.item-list .item-meta {
    font-size: 12px;
    color: #666;
}

/* Day pills for report schedule */
.day-pill {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 999px;
    border: 1px solid #d0d8e4;
    background: #f5f7fa;
    color: #555;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    user-select: none;
    transition:
        background 0.15s,
        color 0.15s,
        border-color 0.15s;
}
.day-pill:hover {
    border-color: #1a56db;
    color: #1a56db;
}
.day-pill-active {
    background: #1a56db;
    color: white;
    border-color: #1a56db;
}

/* Day pills: the native checkbox owns the state and the keyboard, the span is
   the visible pill. The input is visually hidden but stays focusable. */
.day-pill-wrap {
    display: inline-flex;
    align-items: center;
    margin: 2px;
    cursor: pointer;
}
.day-pill-wrap .day-pill-cb {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: 0;
    opacity: 0;
    pointer-events: none;
}
.day-pill-wrap .day-pill-cb:focus-visible + .day-pill {
    outline: 2px solid #1a56db;
    outline-offset: 2px;
}

/* Messages */
.message {
    padding: 12px;
    border-radius: 4px;
    margin-bottom: 15px;
    font-size: 14px;
}

.message.success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.message.error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.message.info {
    background: #e3f2fd;
    color: #0d47a1;
    border: 1px solid #bbdefb;
}

.message.warning {
    background: #fffbeb;
    color: #92400e;
    border: 1px solid #fde68a;
}

/* Auth Box */
.auth-box {
    background: #f8f9fa;
    border: 2px dashed #dee2e6;
    padding: 25px;
    text-align: center;
    border-radius: 8px;
    margin: 15px 0;
}

.auth-code {
    font-size: 32px;
    font-weight: bold;
    letter-spacing: 3px;
    font-family: monospace;
    color: #2c3e50;
    margin: 15px 0;
}

.auth-url {
    color: #3498db;
    word-break: break-all;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 50px;
    color: #6b7280;
}

.empty-state h3 {
    font-size: 18px;
    margin-bottom: 10px;
    color: #666;
}

/* Row layout */
.row {
    display: flex;
    gap: 15px;
    margin-bottom: 15px;
}

.row > * {
    flex: 1;
}

/* Spinner */
.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: 10px;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* Indeterminate progress bar shown while a confirmed action is running.
   A single long request has no measurable progress, so the bar slides. */
.action-progress {
    height: 4px;
    width: 100%;
    margin: 4px 0 2px;
    background: #e8edf4;
    border-radius: 2px;
    overflow: hidden;
}
.action-progress-bar {
    height: 100%;
    width: 40%;
    background: #3498db;
    border-radius: 2px;
    animation: action-progress-slide 1.1s ease-in-out infinite;
}

@keyframes action-progress-slide {
    0% {
        transform: translateX(-100%);
    }

    100% {
        transform: translateX(250%);
    }
}

/* Tabs */
.tabs {
    display: flex;
    border-bottom: 1px solid #ddd;
    margin-bottom: 20px;
    overflow-x: auto;
    flex-wrap: nowrap;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE/Edge */
}
.tabs::-webkit-scrollbar {
    display: none;
} /* Chrome/Safari */

.tab {
    padding: 10px 14px;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    font-size: 14px;
}

.tab:hover {
    background: #f8f9fa;
}

.tab.active {
    border-bottom-color: #1a56db;
    color: #1a56db;
    font-weight: 500;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Keep inactive panels out of rendering, but let the browser remember their
   rendering state. Re-opening a tab then only paints it instead of laying out
   the whole panel again. The report table is big enough for that difference to
   be visible. Browsers without content-visibility keep the display: none
   behaviour above. */
@supports (content-visibility: hidden) {
    .tab-content {
        display: block;
        content-visibility: hidden;
    }

    .tab-content.active {
        content-visibility: visible;
    }
}

.hidden {
    display: none !important;
}

/* Confirmation Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal {
    background: white;
    border-radius: 8px;
    padding: 30px;
    max-width: 450px;
    width: 90%;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.modal h3 {
    margin-bottom: 15px;
    color: #2c3e50;
    font-size: 18px;
}

.modal p {
    margin-bottom: 20px;
    color: #666;
    line-height: 1.5;
}

.modal .warning {
    color: #e74c3c;
    font-weight: 500;
}

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

/* Notification toast. The palette lives here, not in core/ui.js. */
.notification {
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    max-width: 620px;
    padding: 9px 14px;
    border: 1px solid transparent;
    border-radius: 0 0 6px 6px;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.08);
    font-size: 13px;
    font-weight: 500;
    pointer-events: auto;
    transition: opacity 0.4s;
}

.notification-text {
    flex: 1;
}

.notification.success {
    background: #f0fdf4;
    border-color: #bbf7d0;
    color: #166534;
}
.notification.success .notification-icon {
    color: #16a34a;
}

.notification.error {
    background: #fef2f2;
    border-color: #fecaca;
    color: #991b1b;
}
.notification.error .notification-icon {
    color: #dc2626;
}

.notification.warning {
    background: #fffbeb;
    border-color: #fde68a;
    color: #92400e;
}
.notification.warning .notification-icon {
    color: #d97706;
}

.notification.info {
    background: #eff6ff;
    border-color: #bfdbfe;
    color: #1e40af;
}
.notification.info .notification-icon {
    color: #3498db;
}

/* Small status badge. The .badge-* modifiers only set colours. */
.badge {
    font-size: 10px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 4px;
    background: #eee;
    color: #666;
}

/* Help text under a field: one class instead of inline font-size and colour. */
.form-help {
    font-size: 11px;
    line-height: 1.4;
    color: #4b5563;
}

/* Keep a clear gap between a button icon and its label (for example the trash
   icon on the Delete/Remove buttons). */
.modal-actions .btn {
    gap: 8px;
}

/* Standard action row for panels and cards: the primary action sits at the
   bottom right, the same place as the modal footers. */
.form-actions {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
}

/* System Tags Accordion */

.tag-group-details {
    border: 1px solid #e6edf5;
    border-radius: 8px;
    margin-bottom: 16px;
    overflow: hidden;
    background: #fcfdff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.tag-group-details summary {
    padding: 14px 16px;
    background: #fcfdff;
    cursor: pointer;
    font-weight: 700;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    border-bottom: 1px solid transparent;
    font-size: 14px;
}

.tag-group-details[open] summary {
    border-bottom-color: #e6edf5;
}

.tag-group-details summary::-webkit-details-marker {
    display: none;
}

.tag-group-details summary::after {
    content: "▾";
    font-size: 10px;
    color: #6b7280;
    transition: transform 0.2s;
    margin-left: 8px;
    flex-shrink: 0;
}

.tag-group-details[open] summary::after {
    transform: rotate(180deg);
}

#detailsCustomTagRules {
    overflow: visible;
}

.tag-group-content {
    padding: 16px;
}

/* Group header action (for example "Restore Defaults"): a sibling overlay so
   it can sit in the header row without becoming an interactive element inside
   <summary>, which nested-interactive forbids. */
.tag-group-wrap {
    position: relative;
}
.tag-group-header-action {
    position: absolute;
    /* 1px group border + 14px summary padding + half of the 1.6 line box
       (11.2px) minus half the button height (15px). */
    top: 11.2px;
    right: 34px;
    z-index: 1;
}

.tag-group-summary-title {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
}

.tag-group-summary-icon {
    color: #3498db;
    flex-shrink: 0;
}

.lock-icon {
    font-size: 11px;
    color: #4b5563;
    background: #f0f0f0;
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: 500;
    margin-left: 0;
    flex-shrink: 0;
}

.tag-group-details summary .btn {
    margin-left: 0;
    margin-right: 0;
    flex-shrink: 0;
}

.system-tag-item {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-bottom: 1px solid #eee;
}

.system-tag-item:last-child {
    border-bottom: none;
}

.system-tag-item .item-name {
    font-weight: 500;
}

.system-tag-item .item-meta {
    font-size: 12px;
    color: #666;
}

.system-tag-main {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    flex: 1;
}

/* The state pills also carry .tag-rule-pill, so the colour has to be scoped with
   both class names to win against .tag-rule-pill in features.css. */
.tag-rule-pill.system-tag-pill {
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.18);
    font-weight: 600;
}

.tag-rule-pill.system-tag-pill-pending {
    background: #2563eb;
}

.tag-rule-pill.system-tag-pill-success {
    background: #16a34a;
}

.tag-rule-pill.system-tag-pill-notes {
    background: #7c3aed;
}

.tag-rule-pill.system-tag-pill-warning {
    background: #d97706;
}

.auth-alert {
    background: #f8d7da;
    border: 1px solid #f5c6cb;
    color: #721c24;
    padding: 12px 15px;
    border-radius: 4px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 14px;
}

.btn-icon {
    width: 32px;
    height: 32px;
    padding: 0;
    background: none;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition:
        background 0.2s,
        opacity 0.2s;
    border: none;
    flex-shrink: 0;
}

.btn-icon:hover {
    background: #f1f5f9;
}

.btn-icon svg {
    width: 16px;
    height: 16px;
}

.item-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.tag-rule-list {
    border-radius: 8px;
    border: 2px solid transparent;
    transition:
        border 0.2s ease,
        background 0.2s ease;
}

.tag-rule-list.drag-active {
    background: #f8fbff;
    border: 2px dashed #93c5fd;
    border-radius: 8px;
    padding: 4px;
}

.tag-rule-list.drag-active:has(.tag-rule-draggable.dragging:only-child) {
    min-height: 60px;
}

.tag-rule-list:not(.drag-active) {
    border-color: rgba(0, 0, 0, 0.04);
}

.tag-rule-draggable {
    cursor: grab;
    border-left: 3px solid transparent;
    padding-left: calc(var(--tag-rule-left-pad, 8px) + 3px);
    transition:
        border-color 0.15s ease,
        background 0.12s ease,
        transform 0.15s ease,
        box-shadow 0.15s ease,
        padding-left 0.15s ease;
}

.tag-rule-draggable:hover {
    border-left-color: #93c5fd;
    background: rgba(52, 152, 219, 0.035);
}

.tag-rule-draggable.dragging {
    opacity: 0.6;
    background: #f0f7ff;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transform: scale(1.02);
    border-radius: 6px;
    border-left-color: #2563eb;
    z-index: 100;
}

.tag-rule-draggable.dragging * {
    pointer-events: none;
}

.drag-handle {
    display: grid;
    grid-template-columns: repeat(2, 4px);
    gap: 3px 4px;
    padding: 6px 8px 6px 0;
    cursor: grab;
    flex-shrink: 0;
    position: relative;
}

.drag-handle::after {
    content: "";
    position: absolute;
    right: 0;
    top: 4px;
    bottom: 4px;
    width: 1px;
    background: #e2e8f0;
    transition: background 0.12s ease;
}

.tag-rule-draggable.dragging .drag-handle {
    cursor: grabbing;
    background: rgba(52, 152, 219, 0.18);
}

.drag-handle-dot {
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: #b6c1cd;
    opacity: 0.3;
    transition:
        opacity 0.15s ease,
        transform 0.15s ease;
}

.tag-rule-draggable:hover .drag-handle-dot {
    opacity: 0.7;
    transform: scale(1.1);
}

.tag-rule-draggable.dragging .drag-handle-dot {
    opacity: 1;
}

.tag-rule-draggable:hover .drag-handle {
    background: rgba(52, 152, 219, 0.08);
    border-radius: 4px;
}

.drag-handle:hover {
    background: rgba(52, 152, 219, 0.15) !important;
}

.tag-rule-draggable:hover .drag-handle-dot:nth-child(1) {
    transition-delay: 0s;
}
.tag-rule-draggable:hover .drag-handle-dot:nth-child(2) {
    transition-delay: 0.03s;
}
.tag-rule-draggable:hover .drag-handle-dot:nth-child(3) {
    transition-delay: 0.06s;
}
.tag-rule-draggable:hover .drag-handle-dot:nth-child(4) {
    transition-delay: 0.09s;
}
.tag-rule-draggable:hover .drag-handle-dot:nth-child(5) {
    transition-delay: 0.12s;
}
.tag-rule-draggable:hover .drag-handle-dot:nth-child(6) {
    transition-delay: 0.15s;
}

.tag-rule-draggable:hover .drag-handle::after {
    background: #93c5fd;
}

.drop-indicator {
    height: 3px;
    background: #2563eb;
    border-radius: 2px;
    margin: 2px 0;
}

@keyframes dropIndicatorPulse {
    0%,
    100% {
        opacity: 1;
    }
    50% {
        opacity: 0.6;
    }
}

@keyframes indicatorAppear {
    0% {
        opacity: 0;
        transform: scaleY(0.5);
    }
    100% {
        opacity: 1;
        transform: scaleY(1);
    }
}

@keyframes settleDrop {
    0% {
        transform: scale(1.02);
    }
    50% {
        transform: scale(0.98);
    }
    100% {
        transform: scale(1);
    }
}

.tag-rule-draggable.drop-settled {
    animation: settleDrop 0.2s ease-out;
}

.drag-hint-text {
    font-size: 11px;
    color: #4b5563;
    padding: 4px 4px 0;
    display: flex;
    align-items: center;
    gap: 4px;
    user-select: none;
}

/* Long dialogs (e.g. the member editor) must scroll inside the overlay.
   Without this the Save button sits below a fixed, non-scrolling overlay. */
.modal-overlay {
    padding: 16px;
}
.modal {
    max-height: 100%;
    overflow-y: auto;
    margin: auto;
}

/* The switch input is visually hidden, so the focus ring must go on the track. */
.personalization-switch input:focus-visible + .personalization-switch-track {
    outline: 2px solid #1a56db;
    outline-offset: 2px;
}

@media (max-width: 560px) {
    .tab {
        padding: 10px 10px;
        font-size: 13px;
    }
}
