#cip-app {
    margin-top: 20px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;

    /* Farben als Variablen mit Admin-Werten als Default. Das Theme belegt im
       Frontend nur diesen Block neu, statt einzelne Regeln zu ueberschreiben -
       sonst bleibt zwangslaeufig eine liegen (z.B. der weisse Kachelfuss). */
    --cip-tile-bg: #fff;
    --cip-tile-border: #ddd;
    --cip-info-bg: #fdfdfd;
    --cip-info-border: #eee;
    --cip-info-text: #50575e;
    --cip-info-strong: #1d2327;
    --cip-frame: #eee;
    --cip-good: #006799;
    --cip-bad: #cc0000;
    --cip-ok: #008000;
    --cip-neutral: #787c82;
    --cip-muted: #3c434a;
    --cip-overlay-bg: rgba(255, 255, 255, 0.75);
    --cip-overlay-text: #1d2327;
    --cip-ctrl-bg: #f0f0f1;
    --cip-ctrl-border: #8c8f94;
    --cip-ctrl-text: #1d2327;
    --cip-ctrl-on-bg: #2271b1;
    --cip-ctrl-on-text: #fff;
}

/* Frontend Specific Styles */
.cip-frontend { margin: 0; padding: 1em 0; box-shadow: none; border: none; }
.cip-frontend #cip-lifetime-stats,
.cip-frontend .setting-group[data-setting-group="after-upload"],
.cip-frontend .setting-group[data-setting-group="after-download"] input[value="none"],
.cip-frontend label[for*="cip-after-upload"],
.cip-frontend #cip-upload-processed,
.cip-frontend #cip-reset-lifetime-stats,
.cip-frontend #cip-load-from-media /* Hide media load button in frontend */
{ display: none !important; }


#cip-app hr { margin: 25px 0; border: none; border-top: 1px solid #dcdcde; }

/* Accordion Styles */
details.cip-accordion { border: 1px solid #c3c4c7; border-radius: 3px; margin-bottom: 15px; background: #fff; box-shadow: 0 1px 1px rgba(0,0,0,.04);}
details.cip-accordion[open] { border-bottom: 1px solid #c3c4c7; }
details.cip-accordion summary { padding: 10px 15px; font-weight: 600; color: #1d2327; cursor: pointer; background: #f6f7f7; border-bottom: 1px solid transparent; list-style: none; display: flex; align-items: center; justify-content: space-between; transition: background-color 0.1s ease; }
details.cip-accordion[open] summary { border-bottom-color: #e5e5e5; background: #f0f0f1; }
details.cip-accordion summary:hover { background: #f0f0f1; }
details.cip-accordion summary::-webkit-details-marker { display: none; }
details.cip-accordion summary::after { content: '\f140'; font-family: dashicons; font-size: 20px; color: #50575e; transition: transform 0.2s ease-in-out; margin-left: 10px; }
details.cip-accordion[open] summary::after { transform: rotate(180deg); }
.cip-accordion-content { padding: 15px; border-top: 1px solid #e5e5e5;}

/* Upload Area */
.cip-uploader { margin-bottom: 15px; }
.cip-uploader-title { margin: 0 0 10px; padding: 0; }
#cip-drop-zone { border: 2px dashed #c3c4c7; padding: 30px; text-align: center; background-color: #f6f7f7; border-radius: 4px; transition: background-color 0.2s ease, border-color 0.2s ease; margin-top: 10px; position: relative; }
#cip-drop-zone.drag-over { background-color: #e0e5e9; border-color: #949ca1; }
#cip-drop-zone p { margin: 0; color: var(--cip-info-text); }
#cip-file-input-label { color: #007cba; text-decoration: underline; cursor: pointer; }
#cip-file-input-label:hover { color: #005a87; }
#cip-drop-zone #cip-loading-spinner { position: absolute; top: 10px; right: 10px; }


/* Spinner Style & Fallback */
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
.spinner { display: inline-block; width: 20px; height: 20px; border: 3px solid rgba(0, 124, 186, 0.3); border-radius: 50%; border-top-color: #007cba; animation: spin 1s ease-in-out infinite; -webkit-animation: spin 1s ease-in-out infinite; visibility: hidden; }
.spinner.is-active { visibility: visible; }

/* Session Stats */
#cip-session-stats { margin: 15px 0; padding: 10px 15px; border: 1px solid #c3c4c7; border-radius: 4px; font-size: 13px; background-color: var(--cip-ctrl-bg); color: var(--cip-info-text); }
#cip-session-stats .stat-saved { font-weight: bold; color: var(--cip-good); }
#cip-session-stats strong { margin-right: 10px; color: var(--cip-info-strong); }
#cip-session-stats .stat-item { margin-right: 15px; display: inline-block; margin-bottom: 5px;}
#stat-session-formats { font-style: italic; color: var(--cip-neutral);}

/* Main Layout: Previews & Sidebar */
#cip-main-content-area { display: flex; flex-wrap: wrap; gap: 30px; margin-top: 20px; display: none; /* Initially hidden */}
#cip-previews-wrapper { flex: 3 1 600px; min-width: 300px; }
#cip-sidebar { flex: 1 1 300px; min-width: 280px; max-width: 360px; /* Max width set */ }

/* Controls & Settings Area within Sidebar */
#cip-sidebar h2 { font-size: 1.3em; margin-bottom: 15px; padding-bottom: 5px; border-bottom: 1px solid var(--cip-info-border); font-weight: 600; color: var(--cip-info-strong); }
#cip-sidebar h3 { margin-top: 0; margin-bottom: 15px; font-size: 1.1em; color: var(--cip-info-strong); font-weight: 600; }
#cip-sidebar label { margin-bottom: 3px; font-weight: normal; color: var(--cip-info-text); display: inline-block; vertical-align: middle;}
#cip-sidebar input[type="number"], #cip-sidebar select { padding: 5px 8px; border-radius: 3px; border: 1px solid #8c8f94; width: 100%; box-sizing: border-box; margin-bottom: 10px;}
#cip-sidebar input[type="number"]#cip-quality { width: 60px; display: inline-block; margin-left: 5px; margin-bottom: 0; vertical-align: middle;}
#cip-sidebar select#cip-convert-format { display: inline-block; width: auto; margin-bottom: 0; vertical-align: middle;}
#cip-sidebar input[type="radio"] { margin-right: 5px; vertical-align: -2px; }
#cip-sidebar .setting-group { margin-bottom: 15px; }
#cip-sidebar .setting-group label { display: block; margin-right: 0; margin-bottom: 5px; }
#cip-sidebar .setting-group strong { display: block; margin-bottom: 5px; font-weight: 600; }
#cip-sidebar .setting-group small { font-size: 11px; color: var(--cip-neutral); margin-left: 5px; }
#cip-actions-buttons .button { width: 100%; text-align: center; margin-bottom: 5px; margin-right: 0;}
#cip-save-download-buttons .button { width: 100%; text-align: center; margin-right: 0;}
#cip-actions-buttons h3, #cip-save-download-buttons h3 { margin-top: 20px; }
#cip-save-download-buttons { padding-top: 15px; border-top: 1px solid var(--cip-info-border); }
#cip-log-sidebar h3 { margin-top: 0;}


/* Image Grid & Tiles */
.cip-category-container { margin-bottom: 30px; border: 1px solid #ccd0d4; padding: 15px; background-color: #f6f7f7; border-radius: 4px; }
.cip-category-container h2 { margin-top: 0; margin-bottom: 15px; padding-bottom: 10px; border-bottom: 1px solid var(--cip-info-border); display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px 12px; font-size: 1.3em; }
.cip-category-container h2 > label { margin-right: auto; }
/* Spaltenzahl kommt aus --cip-cols (Umschalter im Kategorie-Kopf). minmax(0,1fr)
   statt auto: sonst sprengt ein langer Dateiname die Spur. */
.cip-grid-container { display: grid; grid-template-columns: repeat(var(--cip-cols, 4), minmax(0, 1fr)); gap: 20px; }
#cip-portrait-grid { --cip-cols: 4; }
#cip-landscape-grid { --cip-cols: 3; }
/* repeat() nimmt kein min()/calc(), die Deckelung muss deshalb fest sein. */
@media (max-width: 900px) { .cip-grid-container { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 560px) { .cip-grid-container { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* Spalten-Umschalter */
.cip-cols-switch { display: inline-flex; align-items: center; gap: 2px; font-size: 0.72em; font-weight: normal; }
.cip-cols-switch .cip-cols-label { margin-right: 5px; color: var(--cip-info-text); }
.cip-cols-btn { min-width: 27px; padding: 3px 6px; font: inherit; line-height: 1.3; cursor: pointer; border: 1px solid var(--cip-ctrl-border); background: var(--cip-ctrl-bg); color: var(--cip-ctrl-text); border-radius: 3px; }
.cip-cols-btn:hover { border-color: var(--cip-ctrl-on-bg); }
.cip-cols-btn[aria-pressed="true"] { background: var(--cip-ctrl-on-bg); border-color: var(--cip-ctrl-on-bg); color: var(--cip-ctrl-on-text); }
.cip-tile { position: relative; border: 1px solid var(--cip-tile-border); background-color: var(--cip-tile-bg); display: flex; flex-direction: column; overflow: hidden; transition: opacity 0.3s ease, filter 0.3s ease, max-height 0.35s ease-in-out, margin 0.35s ease-in-out, padding 0.35s ease-in-out, border 0.35s ease-in-out; box-shadow: 0 1px 2px rgba(0,0,0,0.1); border-radius: 3px; }
.cip-tile.uploaded-gray, .cip-tile.downloaded-gray { filter: grayscale(90%); opacity: 0.6; }
.cip-tile.uploaded-hide, .cip-tile.downloaded-hide { opacity: 0; pointer-events: none; max-height: 0 !important; overflow: hidden; border: none !important; margin: 0 !important; padding: 0 !important; }
/* contain statt cover: bei vier Spalten waere ein Mittelausschnitt vom
   Hochformat kaum noch als Bild erkennbar. */
.cip-tile-image-wrapper { position: relative; width: 100%; aspect-ratio: 1 / 1; overflow: hidden; background-color: var(--cip-frame); cursor: zoom-in; }
#cip-portrait-grid .cip-tile-image-wrapper { aspect-ratio: 3 / 4; }
#cip-landscape-grid .cip-tile-image-wrapper { aspect-ratio: 4 / 3; }
.cip-tile-image-wrapper:focus-visible { outline: 2px solid var(--cip-ctrl-on-bg); outline-offset: -2px; }
.cip-tile img { display: block; width: 100%; height: 100%; object-fit: contain; object-position: center center; }
.cip-tile .cip-checkbox { position: absolute; top: 5px; left: 5px; z-index: 10; background-color: rgba(255, 255, 255, 0.7); border-radius: 3px; padding: 2px; transform: scale(1.2); cursor: pointer; }
.cip-tile-info { padding: 8px 10px; font-size: 11px; line-height: 1.45; background-color: var(--cip-info-bg); border-top: 1px solid var(--cip-info-border); min-height: 65px; color: var(--cip-info-text); flex-grow: 1; }
.cip-tile-info strong { color: var(--cip-info-strong); }
.cip-tile-info .info-before, .cip-tile-info .info-after { display: block; margin-bottom: 4px; word-wrap: break-word; }
.cip-tile-info .info-after { margin-top: 4px; }
.cip-tile-info .info-reduction { color: var(--cip-good); font-weight: bold; margin-left: 3px; }
.cip-tile-info .no-reduction { color: var(--cip-neutral); margin-left: 3px; }
.cip-tile-info .info-size-up { color: var(--cip-bad); margin-left: 3px; }
.cip-tile-info .info-status-error { color: var(--cip-bad); }
.cip-tile-info .info-status-uploaded { color: var(--cip-ok); }
.cip-tile-info .info-status-downloaded { color: var(--cip-muted); }
.cip-tile-info .info-filename { display: block; margin-top: 4px; word-break: break-all; }

/* Aktionszeile: erst sichtbar, wenn es etwas herunterzuladen gibt. */
.cip-tile-actions { display: none; align-items: center; gap: 8px; padding: 0 10px 9px; background-color: var(--cip-info-bg); }
.cip-tile.is-processed .cip-tile-actions { display: flex; }
.cip-tile-download { font: inherit; font-size: 11px; padding: 4px 10px; cursor: pointer; border: 1px solid var(--cip-ctrl-border); background: var(--cip-ctrl-bg); color: var(--cip-ctrl-text); border-radius: 3px; }
.cip-tile-download:hover { border-color: var(--cip-ctrl-on-bg); }
.cip-tile-fetched { display: none; font-size: 11px; color: var(--cip-ok); }
.cip-tile--fetched .cip-tile-fetched { display: inline; }
.cip-tile .cip-status-overlay { position: absolute; top: 0; left: 0; right: 0; bottom: 0; background-color: var(--cip-overlay-bg); display: flex; justify-content: center; align-items: center; font-size: 1em; font-weight: bold; color: var(--cip-overlay-text); z-index: 5; text-align: center; padding: 5px; opacity: 0; transition: opacity 0.3s ease; pointer-events: none; border-radius: 3px 3px 0 0; }
.cip-tile .cip-status-overlay.visible { opacity: 1; }
.cip-tile .cip-status-overlay.processing { color: var(--cip-good); background-color: var(--cip-overlay-bg); }
.cip-tile .cip-status-overlay.success { background-color: rgba(0, 167, 98, 0.85); color: white; }
.cip-tile .cip-status-overlay.error { background-color: rgba(220, 50, 50, 0.85); color: white; }
.cip-tile .cip-status-overlay.uploaded { background-color: rgba(114, 119, 124, 0.85); color: white; }
.cip-tile .cip-status-overlay.downloaded { background-color: rgba(114, 119, 124, 0.85); color: white; }
.cip-tile.processing .cip-tile-image-wrapper { opacity: 0.7; }

/* Button Styling */
#cip-upload-processed, #cip-download-zip, #cip-reset-lifetime-stats, .cip-action-button, #cip-refresh-images, #cip-clear-all { transition: background-color 0.2s ease-in-out, border-color 0.2s ease-in-out, opacity 0.2s ease-in-out; margin-right: 0; margin-bottom: 5px; }
#cip-upload-processed { background-color: #2271b1; color: white; border-color: #1f6aa1; }
#cip-upload-processed:hover { background-color: #1f6aa1; border-color: #1a5a8e; color: white; }
#cip-download-zip { background-color: #3c434a; color: white; border-color: #32373c; }
#cip-download-zip:hover { background-color: #32373c; border-color: #2a2f33; color: white; }
.cip-action-button { background-color: #f0f0f1; border-color: #8c8f94; color: #1d2327;}
.cip-action-button:hover { background-color: #e0e1e3; border-color: #6a6e73;}
.cip-action-button.button-primary { background-color: #007cba; color: white; border-color: #0071a1;}
.cip-action-button.button-primary:hover { background-color: #006ba1; border-color: #005a87;}
#cip-reset-lifetime-stats, #cip-clear-all { background-color: #d63638; color: white; border-color: #b62f2f; }
#cip-reset-lifetime-stats:hover, #cip-clear-all:hover { background-color: #b62f2f; border-color: #a0292a; }
#cip-refresh-images { background-color: #f0f0f1; border-color: #8c8f94; color: #1d2327;}
#cip-refresh-images:hover { background-color: #e0e1e3; border-color: #6a6e73;}
#cip-upload-processed:disabled, #cip-download-zip:disabled, #cip-reset-lifetime-stats:disabled, .cip-action-button:disabled, #cip-refresh-images:disabled, #cip-clear-all:disabled { background-color: #a7aaad !important; border-color: #9a9c9f !important; color: #eaeaec !important; cursor: not-allowed !important; opacity: 0.7 !important; }

#cip-log-output { height: 250px; overflow-y: scroll; padding: 5px; font-size: 12px; line-height: 1.4; background-color: #fff; border: 1px solid #e5e5e5; }

/* Namensschema */
#cip-sidebar .setting-group[data-setting-group] { margin-bottom: 15px; padding-top: 10px; border-top: 1px dashed var(--cip-info-border); }
#cip-naming-fields { margin-top: 8px; padding-left: 22px; }
#cip-naming-fields.is-off { opacity: 0.45; }
#cip-naming-fields label { font-size: 12px; }
#cip-naming-fields .cip-naming-row { display: flex; gap: 14px; margin-top: 6px; }
#cip-sidebar #cip-naming-fields input[type="number"] { width: 68px; display: inline-block; margin-bottom: 0; }
#cip-sidebar #cip-naming-prefix { margin-bottom: 0; }

/* Lifetime Stats */
#cip-lifetime-stats { font-size: 13px; border: 1px solid #c3c4c7; color: #3c434a; }
#cip-lifetime-stats h3 { margin-bottom: 10px; color: #1d2327;}
#cip-lifetime-stats ul { margin-top: 5px; margin-bottom: 10px; margin-left: 20px; list-style: disc; }
#cip-lifetime-stats p { margin: 5px 0; }
#cip-lifetime-stats strong { color: #1d2327; }
#cip-lifetime-stats small { color: #787c82; font-size: 11px; }
#cip-lifetime-stats-content.loading { color: #787c82; font-style: italic; }

/* Media Modal Styles (Backend only) */
#cip-media-modal { display: none; position: fixed; z-index: 10000; left: 0; top: 0; width: 100%; height: 100%; overflow: auto; background-color: rgba(0,0,0,0.4); }
.cip-modal-content { background-color: #fefefe; margin: 5% auto; padding: 20px; border: 1px solid #888; width: 80%; max-width: 700px; border-radius: 4px; box-shadow: 0 5px 15px rgba(0,0,0,.5); }
.cip-modal-close { color: #aaa; float: right; font-size: 28px; font-weight: bold; }
.cip-modal-close:hover, .cip-modal-close:focus { color: black; text-decoration: none; cursor: pointer; }
#cip-media-breadcrumbs { margin-bottom: 15px; font-size: 14px; }
#cip-media-breadcrumbs a { text-decoration: none; color: #0073aa; }
#cip-media-breadcrumbs a:hover { text-decoration: underline; }
#cip-media-breadcrumbs span { margin: 0 5px; }
#cip-media-folder-list ul, #cip-media-image-list ul { list-style: none; padding: 0; margin: 0; }
#cip-media-folder-list li a { display: block; padding: 8px 10px; text-decoration: none; color: #0073aa; border-bottom: 1px solid #eee; }
#cip-media-folder-list li a:hover { background-color: #f0f0f0; }
#cip-media-folder-list li a::before { font-family: dashicons; content: "\f157"; margin-right: 8px; } /* Folder icon */
#cip-media-image-list li { display: flex; align-items: center; padding: 8px 0; border-bottom: 1px solid #eee; }
#cip-media-image-list li:last-child { border-bottom: none; }
#cip-media-image-list input[type="checkbox"] { margin-right: 10px; }
#cip-media-image-list img.thumbnail { width: 40px; height: 40px; object-fit: cover; margin-right: 10px; border: 1px solid #ddd; }
#cip-media-image-list .filename { flex-grow: 1; }
#cip-media-image-list .filesize { font-size: 12px; color: #777; margin-left: 10px; }
#cip-media-modal-actions { margin-top: 20px; text-align: right; }
/* Lightbox
   Bewusst immer dunkel, im Backend wie im Frontend - ein Bild beurteilt man
   nicht gegen eine weisse Flaeche. Deshalb hier keine Theme-Variablen. */
#cip-lightbox { display: none; position: fixed; inset: 0; z-index: 100000; background: rgba(0, 0, 0, 0.88); padding: 20px; }
#cip-lightbox.is-open { display: flex; flex-direction: column; align-items: center; justify-content: center; }
.cip-lb-stage { display: flex; align-items: center; justify-content: center; gap: 14px; max-width: 100%; }
#cip-lb-img { max-width: 78vw; max-height: 74vh; object-fit: contain; background-image: linear-gradient(45deg, #2a2a2a 25%, transparent 25%, transparent 75%, #2a2a2a 75%), linear-gradient(45deg, #2a2a2a 25%, #1e1e1e 25%, #1e1e1e 75%, #2a2a2a 75%); background-size: 20px 20px; background-position: 0 0, 10px 10px; box-shadow: 0 14px 50px rgba(0, 0, 0, 0.6); }
.cip-lb-nav { flex: none; width: 46px; height: 68px; font-size: 24px; line-height: 1; cursor: pointer; border: none; border-radius: 6px; background: rgba(255, 255, 255, 0.12); color: #fff; }
.cip-lb-nav:hover:not(:disabled) { background: rgba(255, 255, 255, 0.26); }
.cip-lb-nav:disabled { opacity: 0.2; cursor: default; }
.cip-lb-close { position: absolute; top: 18px; right: 22px; width: 40px; height: 40px; font-size: 24px; line-height: 1; cursor: pointer; border: none; border-radius: 6px; background: rgba(255, 255, 255, 0.12); color: #fff; }
.cip-lb-close:hover { background: rgba(255, 255, 255, 0.26); }
.cip-lb-bar { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 8px 18px; margin-top: 16px; max-width: 82vw; font-size: 13px; color: #fff; text-align: center; }
.cip-lb-caption { color: rgba(255, 255, 255, 0.78); word-break: break-all; }
.cip-lb-toggle { display: inline-flex; gap: 3px; }
.cip-lb-toggle button { padding: 5px 13px; font: inherit; font-size: 12px; cursor: pointer; border: 1px solid rgba(255, 255, 255, 0.28); border-radius: 4px; background: transparent; color: #fff; }
.cip-lb-toggle button[aria-pressed="true"] { background: #fff; border-color: #fff; color: #111; }
.cip-lb-toggle button:disabled { opacity: 0.3; cursor: default; }
@media (max-width: 620px) {
    .cip-lb-nav { width: 38px; height: 54px; font-size: 20px; }
    #cip-lb-img { max-width: 88vw; max-height: 64vh; }
}
html.cip-lb-lock { overflow: hidden; }
